Get BoundField value in GridView RowDataBound event

baros picture baros · Apr 11, 2013 · Viewed 15k times · Source

I want to take LangId value in RowDataBound function. How to do this?

<asp:BoundField DataField="LangId" HeaderText="LangId" Visible="false" />

protected void grdList_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // need LangId
        ImageButton imgBtn = (ImageButton)e.Row.FindControl("imgBtnDelete");
        imgBtn.Visible = false;
    }
}

Answer

Praveen Nambiar picture Praveen Nambiar · Apr 11, 2013

There are a couple of ways to do it. Maybe more.

<asp:BoundField DataField="LangId" HeaderText="LangId" Visible="false" />

protected void grdList_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       string langId = e.Row.Cells[columnIndex].Text; // one of the ways

       string langId2 = DataBinder.Eval(e.Row.DataItem, "LangId").ToString(); // one of the other ways
    }
}