如方便,请关注,必回关,谢谢!
前台代码
<asp:TemplateField HeaderText="出仓">
<ItemTemplate>
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
</ItemTemplate>
</asp:TemplateField>
后台代码
protected void Button2_Click(object sender, EventArgs e)
{
//sender不是button也不会报错,btn会被赋值null,所以后续要判断btn是否为null
Button btn = sender as Button;
if(btn!=null){
//两个Parent就可以得到GridviewRow对象
GridViewRow row = btn.Parent.Parent as GridViewRow;
string a = row.Cells[1].Text.ToString();
string b = row.Cells[0].Text.ToString();
string s_url = "WebForm1.aspx?statu="+b+"&name=" +a;
Response.Redirect(s_url);
}
}
这里就传递了该行的第一个单元格和第二个单元格的值到了WebForm1.aspx页面。
获取值就是
string name= Request.QueryString["name"];
string statu = Request.QueryString["statu"];
实践可以解决问题。