您的位置:首页 > 其它

GridView模板列添加删除按钮

2013-01-17 09:47 351 查看
GridView模板列添加删除按钮

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="job_id"
OnRowCommand="GridView1_RowCommand" >
<Columns>
<asp:BoundField DataField="job_id" />
<asp:BoundField DataField="max_lvl" />
<asp:BoundField DataField="min_lvl" />
<asp:ButtonField ButtonType="Button" CommandName="aa" Text="删除" />
</Columns>
</asp:GridView>

在GridView里面添加个ButtonField 类型是Button的 ,还有关联事件名要起一个名字,因为后面删除要用到这个

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "aa")//aa是关联的事件名
{
int index = Convert.ToInt32(e.CommandArgument);//获取命令的参数
int iLeagueID = Convert.ToInt32(this.GridView1.DataKeys[index].Value);//获取当前点击列的ID号
Response.Write( "<script>alert('" + iLeagueID + "')</script>");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: