在GridView中编辑模板列按钮,然后传递按钮对应行的某一单元格的值

来源:互联网 发布:用友软件成都分公司 编辑:程序博客网 时间:2024/05/29 19:59

如方便,请关注,必回关,谢谢!

前台代码

  <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"];

实践可以解决问题。

阅读全文
0 0
原创粉丝点击