1. the html markup

<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="true" PageSize="" OnPageIndexChanging="GridView1_PageIndexChanging" AutoGenerateColumns="false" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White" RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("Id", "~/ThreadsTest/GridView/DetailsInformation.aspx?Id={0}") %>' Text='<%#Eval("Id") %>'>></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="true" SelectText="View Details" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="" />
<asp:BoundField DataField="City" HeaderText="City" ItemStyle-Width="" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" NavigateUrl='<%# string.Format("~/ThreadsTest/GridView/DetailsInformation.aspx?Id={0}&Name={1}&City={2}", HttpUtility.UrlEncode(Eval("Id").ToString()), HttpUtility.UrlEncode(Eval("Name").ToString()), HttpUtility.UrlEncode(Eval("City").ToString())) %>' Text="View Details" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnExportToEXCEL" runat="server" Text="Export to Excel" OnClick="btnExportToEXCEL_Click"/>
<br />
<hr />
<asp:GridView ID="GridView2" runat="server" AllowPaging="true" OnRowCommand="GridView2_RowCommand" PageSize="" OnPageIndexChanging="GridView2_PageIndexChanging" AutoGenerateColumns="false" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White" RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000">
<Columns> <asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="" />
<asp:BoundField DataField="City" HeaderText="City" ItemStyle-Width="" />
<asp:CommandField ShowSelectButton="true" SelectText="View Details" />
</Columns>
</asp:GridView>
</div>

2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Drawing; namespace _201502ThreadsTest.ThreadsTest
{
public partial class PassHyperLinkInGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//BindGridview(GridView1);
//BindGridview(GridView2);
}
}
//Bind Gridview
public void BindGridview(GridView grv)
{
string sql = "select * from Customer";
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString))
{
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
sda.Fill(dt); grv.DataSource = dt;
grv.DataBind();
}
} //Paging
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGridview(GridView1);
}
//Export to Excel
protected void btnExportToEXCEL_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
GridView1.AllowPaging = false;
this.BindGridview(GridView1);
GridView1.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in GridView1.HeaderRow.Cells)
{
cell.BackColor = GridView1.HeaderStyle.BackColor;
}
foreach (GridViewRow row in GridView1.Rows)
{
row.BackColor = Color.White;
foreach (TableCell cell in row.Cells)
{
if (row.RowIndex % == )
{
cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
}
else
{
cell.BackColor = GridView1.RowStyle.BackColor;
}
cell.CssClass = "textmode";
}
}
GridView1.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
} protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
int Id = Convert.ToInt32(GridView2.Rows[index].Cells[].Text);
Session["Id"] = Id;
Response.Redirect("~/ThreadsTest/GridView/DetailsInformation.aspx");
} protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
this.BindGridview(GridView2);
}
}
}

3. 目标页

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="">
<tr>
<td>
<b>Id</b>
</td>
<td>
<asp:Label ID="lblId" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<b>Name</b>
</td>
<td>
<asp:Label ID="lblName" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<b>City</b>
</td>
<td>
<asp:Label ID="lblCity" runat="server"></asp:Label>
</td>
</tr>
</table>
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/ThreadsTest/GridView/PassHyperLinkInGridView.aspx">Back to Previous page </asp:HyperLink>
</div>
</form>
</body>
</html>
 if (!IsPostBack)
{
//lblId.Text = Request.QueryString["Id"];
//lblName.Text = Request.QueryString["Name"];
//lblCity.Text = Request.QueryString["City"]; string id = Session["Id"].ToString();
Response.Write(id);
}

使用超链接跳转页面(GridView)的更多相关文章

  1. css常用属性之绝对定位、相对定位、滚动条属性、背景图属性、字体、鼠标、超链接跳转页面

    1.绝对定位position: fixed(比如广告页面向下滑动的时候,页面最上方有个标题不能随之滑动,就需要用到position: fixed,同时还需要用到一个标签(标签高度很高才会出现滚动的情况 ...

  2. 【2017-05-21】WebForm跨页面传值取值、C#服务端跳转页面、 Button的OnClientClick属性、Js中getAttribute和超链接点击弹出警示框。

    一.跨页面传值和取值: 1.QueryString - url传值,地址传值 优缺点:不占用服务器内存:保密性差,传递长度有限. 通过跳转页面路径进行传值,方式: href="地址?key= ...

  3. WebForm跨页面传值取值、C#服务端跳转页面、 Button的OnClientClick属性和超链接点击弹出警示框

    一.跨页面传值和取值: 1.QueryString - url传值,地址传值 优缺点:不占用服务器内存:保密性差,传递长度有限. 通过跳转页面路径进行传值方式: href="地址?key=v ...

  4. asp.net跳转页面的三种方法比较(转)

    2006-10-20 14:32 [小 大] 来源: 博客园 评论: 0分享至: 百度权重查询 词库网 网站监控 服务器监控 SEO监控 手机游戏 iPhone游戏 今天老师讲了三种跳转页面的方法,现 ...

  5. JS定时刷新页面及跳转页面

    JS定时刷新页面及跳转页面 Javascript 返回上一页1. Javascript 返回上一页 history.go(-1), 返回两个页面: history.go(-2); 2. history ...

  6. Webform Session、Cookies传值,跳转页面方式

    Session:每个独立的浏览器都会创建一个独立的Session,不是一台电脑一个Session 存放位置:服务器上 作用:只要里面有内容,那么这个网站中所有的C#端都能访问到这个变量 优点:安全,速 ...

  7. 跳转页面,传递参数——android

    android 跳转页面并传递对象(实体类)——项目中是集港收货类 网上资料:两种传递方法Serializable,parcelable 优劣比较:Serializable数据更持久化,网络传输或数据 ...

  8. Response.Redirect 无法跳转页面

    错误现象:Response.Redirect(Server.MapPath("BackIndex.aspx")); 打断点测试执行了这一句,Server.MapPath(" ...

  9. xamarin.ios 跳转页面

    一:用Segue跳转页面 按住Ctrl连线,选择show,后台覆写 ShouldPerformSegue方法,返回True跳转,False取消跳转.   二:通过代码跳转至StoryBoard页面 U ...

随机推荐

  1. postman下载和安装

    插件下载地址:http://download.csdn.net/download/zhanghaofor/8244137 下载后解压缩,里面有安装方法 1.找到后缀为crx的文件,将后缀改成rar并解 ...

  2. 循环-21. 求交错序列前N项和

    /* * Main.c * C21-循环-21. 求交错序列前N项和 * Created on: 2014年8月18日 * Author: Boomkeeper ***********测试通过**** ...

  3. 为过程或函数sp_Adduser指定了过多的参数

    前些天写用户注册模块,用存储过程添加用户,一开始就报“为过程或函数sp_Adduser指定了过多的参数”.仔细检查数据层的用户添加函数,结果在为存储过程添加sqlparameter参数的时候,数组给写 ...

  4. 阿里云ECS每天一件事D5:安装php5.4.34

    原本是想把php和nginx合在一起来说的,不过考虑后,还是分开来做吧,已熟悉的更透彻一些. 1.准备类库 yum install autoconf automake libtool re2c fle ...

  5. QML开源游戏

    http://google.github.io/VoltAir/doc/main/html/index.htmlhttp://blog.qt.io/blog/2010/02/26/qt-box2d-i ...

  6. Bootstrap禁用响应式布局

    在Bootstrap中极其重要的一个技术内容便是响应式布局了,一次编码针对不同设备终端的强大能力使得响应式技术愈发流行. 不过正所谓"萝卜青菜各有所爱",如果你想要使用Bootst ...

  7. HDU 5800 To My Girlfriend(单调DP)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5800 [题目大意] 给出一个容量上限s,f[i][j][k][l][m]表示k和l两个物品不能选,i ...

  8. nmon related

    nmon related pGraph (supports nmon) https://www.ibm.com/developerworks/community/wikis/home?lang=en# ...

  9. 每天学点Linux:二

    关于输入输出和重定向: 默认情况下标准I/O的输入为键盘,输出为显示屏.输入和输出可以通过符号‘>’进行重定向. 例如可以通过命令:$>newfile 来创建一个新文件(如果newfile ...

  10. 再学习sqlhelper

    在机房收费重构系统的时候,第一次学习sqlhelper.当时感觉比较简单,没有写博客总结,现在又经过了图书馆的学习,感觉还是有必要写一写的. SqlHelper是一个基于.NETFramework的数 ...