日期:2014-05-18  浏览次数:20379 次

本人菜鸟,传参
gridView 在编辑列中ItemTemplete中BUTTON点击后到另一个页面 怎样传参

------解决方案--------------------
我想这里的传值包括两个知识点
1. 点击button 时 如何执行相应的事件
2 如何把相应的值绑定上去
下面的代码测试成功
设置GridView1 的commandname =open 
C# code
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string name = e.CommandName;
        int index = Convert.ToInt32(e.CommandArgument);
        string a = GridView1.Rows[index].Cells[1].Text; 
        if (name == "open")
        {
            Response.Redirect("a.aspx?id="+a); 
        }
 
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Button bt = (Button)e.Row.Cells[0].FindControl("Button2");
            bt.CommandArgument = e.Row.RowIndex.ToString(); 
        }
    }