我没有得到行数据绑定事件中特定行的值,值为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();
}
答案 0 :(得分:4)
您要查找的值存储在标签控件中,而不是存储在表格单元格中。因此,您需要在该行上使用FindControl
来访问lbl_TodayPos
:
Label myLabel = (Label)GrdKeyWord.Rows[rowindex].FindControl("lbl_TodayPos");
string value = myLabel.Text;
如果您自动生成 gridview中的列,或者您使用了'BoundField'(而不是TemplateField
),则可以使用.Cells[]
。因为,在这种情况下,您将gridview呈现为具有表格单元格的纯html表。