简体   繁体   中英

cell value in gridview is not getting in asp.net

im not getting the valu of specic row in row data bound event , value coming null;

 <asp:TemplateField>
                <HeaderTemplate>
                    Today's pos
                </HeaderTemplate>
                <ItemTemplate>
                   <asp:Label ID="lbl_TodayPos" runat="server" Text='<%# Eval("CurrentPosition") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

aspx.cs code
 protected void GrdKeyWord_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      string value = GrdKeyWord.Rows[rowindex].Cells[5].ToString();
}

The value you are looking for is stored in a label control not in a table cell. Therefore, you need to use FindControl on that row to access the lbl_TodayPos :

Label myLabel = (Label)GrdKeyWord.Rows[rowindex].FindControl("lbl_TodayPos");
string value = myLabel.Text;

If you autogenerate the columns in the gridview, or if you used 'BoundField' (instead of TemplateField ) you could use .Cells[] . Because, in this case, you would have gridview rendered as pure html table with table cells.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM