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. android studio2.0 搭建Robotium环境--有被测源代码的情况下

    1.导入robotium-solo-5.2.1.jar 包    导入junit:4.12.jar2.app- -src- -main- -libs 或者app-libs下 复制进去后,右键add a ...

  2. XHProf 初探

    XHProf是一个分层PHP性能分析工具.它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况.一个函数的开销,可细分成调用者和被调用者的开销,XHProf数据收集阶段,它记录调 ...

  3. 用extundelete恢复rm -rf删的文件

    “慎用rm -rf命令,除非你知道此命令带来的后果.”这是一条Linux用户守则,虽然大多数用户都明白这条语句的含义,但是我觉得还需要完善一下,为这条语句加 上一个使用前提:在你确认自己拥有清醒头脑, ...

  4. SQL存储过程动态查询数据区间

    以前经常看到人查询数据库采用left join及case方式,一条一条的枚举查询整个数据的数据区间方法可行,但是数据一但很大,枚举就死悄悄,在网上查看,几乎全是照抄case ,left join枚举无 ...

  5. cocos2d-x-3.1 Text Labels(官方正式译文)

    介绍 cocos2d支持(true type字体)标签,和纹理地图集标签. LabelTTF 标签的优缺点: 全部 TTF 字体的长处: 随意大小,支持调整字距. 易于使用. 不须要外部编辑器. 创建 ...

  6. externkeyword放到函数体内而导致的linkage问题

    不少人都知道,C/C++语言编程时,假设要引用在别的C/C++文件里定义的变量或函数,必须extern一下,才干使用 另一些人知道,这个extern事实上能够放在函数体内声明,这么做的理由是不想让其它 ...

  7. C# DateTime.Now 用法小记

    1.DateTime.Now   获取时间跟系统当前时间一直并且格式一直,如系统时间带有星期几,获取的时间也会带有 2,以下为拷贝前人总结的: //2008年4月24日 System.DateTime ...

  8. C# 获得当前应用程序路径

    1.获得当前应用程序的路径最稳定的方法:AppDomain.CurrentDomain.BaseDirectory 生成的路径:../项目名称/bin/Debug下的路径

  9. The Painter's Partition Problem Part I

    (http://leetcode.com/2011/04/the-painters-partition-problem.html) You have to paint N boards of leng ...

  10. css中z-index属性(标签层叠次序)

    定义和用法 z-index 属性设置元素的堆叠顺序.拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面. 注释:元素可拥有负的 z-index 属性值. 注释:Z-index 仅能在定位元素上奏 ...