您的位置:首页 > 其它

获取某行的字段ID值(GridView模板列)

2007-06-15 16:56 393 查看
aspx页面

<asp:GridView runat="server" ID="grd" AutoGenerateColumns="false" DataKeyNames="leagueID" OnRowCommand="grd_RowCommand" OnRowCreated="grd_RowCreated">
<Columns>
<asp:TemplateField HeaderText="我要加入">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
 <asp:Button runat="server" ID="btnJoin" Text="加 入" CommandName="btnJoin" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

aspx.cs类文件

protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)

protected void grd_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnJoin = (Button)e.Row.FindControl("btnJoin");
btnJoin.CommandArgument = e.Row.RowIndex.ToString();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: