这是我在.cs文件中的代码:
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
name = e.Row.Cells[0].Text;
}
这是GridView的.aspx代码:
<asp:GridView ID = "GridView2" runat ="server" DataSourceID = "sourceProducts" AutoGenerateColumns = "False" AllowSorting="True" Width="100%" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:BoundField DataField = "resultId" HeaderText = "Result Id" />
<asp:BoundField DataField = "runOwner" HeaderText = "Owner" />
</Columns>
</asp:GridView>
我想获得第一列的值是resultId。
答案 0 :(得分:0)
您应该从RowDataBoundEvent上的数据源读取值而不是单元格。
示例:
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView d = (DataRowView)e.Row.DataItem;
name = d["resultId"].ToString();
}