在 GridView RowDataBound 事件中获取 BoundField 值

bar*_*ros 2 c# asp.net gridview boundfield

LangId我想在 RowDataBound 函数中获取值。这个怎么做?

<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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Pra*_*iar 5

有几种方法可以做到这一点。也许更多。

<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
    }
}
Run Code Online (Sandbox Code Playgroud)