日期:2014-05-18 浏览次数:21055 次
DataRowView dgv=this.DataGridView1.CurrentRow.DataBoundItem as DataRowView; DataRow currentRow=dgv.Row; string id=currentRow["ID"];
------解决方案--------------------
使用模板列,传什么都可以啊
------解决方案--------------------
你放到 Button等等的CommandArgument里面,
e.CommandArgument
得到
Response.Redirect("x.aspx?id="+e.CommandArgument)下一个页面
------解决方案--------------------
<%@ Page Language="C#" AutoEventWireup="true" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("ID", typeof(System.Int32))); dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String))); for (int i = 0; i < 8; i++) { dr = dt.NewRow(); dr[0] = i * i; dr[1] = "【孟子E章】" + i.ToString(); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "NextPage") { Response.Redirect("http://dotnet.aspx.cc/?id=" + e.CommandArgument); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand" DataKeyNames="ID" AutoGenerateColumns="false"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:Button ID="Button1" runat="server" CommandName="NextPage" CommandArgument='<%#Eval("ID") %>' Text="测试" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form> </body> </html>