[英]cell value in gridview is not getting in asp.net
我沒有得到特定數據在行數據綁定事件中的值,值為空;
<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();
}
您要查找的值存儲在標簽控件中,而不存儲在表格單元中。 因此,您需要在該行上使用FindControl
來訪問lbl_TodayPos
:
Label myLabel = (Label)GrdKeyWord.Rows[rowindex].FindControl("lbl_TodayPos");
string value = myLabel.Text;
如果您自動生成 gridview中的列,或者使用了'BoundField'(而不是TemplateField
),則可以使用.Cells[]
。 因為在這種情況下,您會將gridview渲染為帶有表格單元格的純html表格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.