日期:2014-05-17 浏览次数:20439 次
<%@ Page Language="C#" EnableViewState="true" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser"); dataTable1.Columns.Add(new System.Data.DataColumn("Id", typeof(System.Int32))); dataTable1.Columns.Add(new System.Data.DataColumn("UserName", typeof(System.String))); Random r = new Random(); for (int i = 0; i < 8; i++) { dataTable1.Rows.Add(i, "名称" + i); } this.GridView1.DataSource = dataTable1; this.GridView1.DataBind(); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { HyperLink h = e.Row.Cells[0].Controls[0] as HyperLink; h.NavigateUrl = "~/b.aspx?id=" + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(DataBinder.Eval(e.Row.DataItem, "Id").ToString())); } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>dddd</title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:HyperLinkField DataTextField="UserName" /> </Columns> </asp:GridView> </form> </body> </html>
------解决方案--------------------
举一反三呀亲,真得喂到嘴里才能吃么?
h.NavigateUrl = "~/b.aspx?id=" + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(DataBinder.Eval(e.Row.DataItem, "Id").ToString()));