ASP.new Web开发中。在GridView里最后一个字段放了按钮,怎么使点击那按钮后。将该行的某自动显示在文本上
2个回答
展开全部
前台GridView中:
<asp:GridView id= "gv " runat= "server " autoGenerateColumns= "false " OnRowCommand= "gv_RowCommand "> //此处需要rowcommand事件响应按钮点击
<columns>
<asp:ButtonField CommandName= "button_1 " Text= "按钮 " /> //此处需要设置CommandName,后台需要根据这个判断点击了按钮
<asp:BoundField HeaderText= "姓名" DataField= "my_name " />
</columns>
</asp:GridView>
后台:
//写RowCommand事件
private void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "button_1 ") //前面的CommandName在这里用了
{
int rowIndex = int.Parse(e.CommandArgument.ToString());
this.textbox1.Text = gv.Rows[rowIndex].Cells[1].Text; //根据你的姓名列位置,修改Cells索引值
}
}
<asp:GridView id= "gv " runat= "server " autoGenerateColumns= "false " OnRowCommand= "gv_RowCommand "> //此处需要rowcommand事件响应按钮点击
<columns>
<asp:ButtonField CommandName= "button_1 " Text= "按钮 " /> //此处需要设置CommandName,后台需要根据这个判断点击了按钮
<asp:BoundField HeaderText= "姓名" DataField= "my_name " />
</columns>
</asp:GridView>
后台:
//写RowCommand事件
private void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "button_1 ") //前面的CommandName在这里用了
{
int rowIndex = int.Parse(e.CommandArgument.ToString());
this.textbox1.Text = gv.Rows[rowIndex].Cells[1].Text; //根据你的姓名列位置,修改Cells索引值
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询