aspx页面:
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
ReadOnly="True" SortExpression="id" Visible="False" />
<asp:BoundField HeaderText="步骤">
<HeaderStyle Width="50px" />
</asp:BoundField>
</Columns>
.cs文件动态生成行号
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
e.Row.Cells[1].Text = Convert.ToString(e.Row.RowIndex + 1);
}
}
在RowCommand中获取行号
在模板列中添加=<%# Container.DataItemIndex + 1 %>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false"
CommandName="modify" Text="修改" CommandArgument=<%# Container.DataItemIndex + 1 %>></asp:LinkButton>
</ItemTemplate>
cs文件
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView gv = ((GridView)sender);
int rowNum = int.Parse(e.CommandArgument.ToString()) - 1;
txbBeizhu.Text = gv.Rows[rowNum].Cells[2].Text;
ModalPopupExtender1.Show();
}