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