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. 与《YII框架》不得不说的故事—5篇目录

    与<YII框架>不得不说的故事—基础篇 第1章 课程目标 1-1 课程目标 (00:54) 第2章 课前知识准备 2-1 YII的启动和安装 (05:12) 2-2 YII请求处理流程 ( ...

  2. MD5 加密 以及 加盐加密

    这是MD5加密 - (NSString *)MD5Hash { const char *cStr = [self UTF8String]; unsigned char result[16]; CC_M ...

  3. 帝国cms中上一篇与下一篇个性化灵动标签调出

    这里的上下篇是用灵动标签制作,可以更为个性化 下一篇 <a href="<?phpecho $bqsr[titleurl];$next='true';?>"> ...

  4. Using SetWindowRgn

    Using SetWindowRgn Home Back To Tips Page Introduction There are lots of interesting reasons for cre ...

  5. apache 支持 php

    找到 httpd 的配置文件:一般在 /etc/httpd/conf 编辑:vi httpd.conf 配置 httpd.conf 让apache支持PHP: # vi /usr/local/apac ...

  6. The Highest Mark(01背包)

    The Highest Mark Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  7. 飘逸的python - 有的升序有的降序的情况下怎么多条件排序

    之前在统计导出各区服玩家消费的时候需要进行升序降序混搭的多条件排序. 需求是这样的.区服从小到大排,如果区服相同,则按消费从大到小排. 实现方法是利用python的sort算法是稳定排序,对数据进行多 ...

  8. g711u与g729比較编码格式

    •711a-编解码格式为G.711 alaw •g711u-编解码格式为G.711 ulaw (the default) •g729-编解码格式为G.729 •g729a-编解码格式为G.729a 上 ...

  9. php 求水仙花数优化

    水仙花数是指一个n位数(n>=3),它每一个位上数字的n次幂之和等于它本身,n为它的位数.(比如:1^3+5^3+3^3 = 153) 水仙花数又称阿姆斯特朗数. 三位的水仙花数有4个:153, ...

  10. redis的分布式解决方式--codis

    codis是豌豆荚开源的分布式server.眼下处于稳定阶段. 原文地址:https://github.com/wandoulabs/codis/blob/master/doc/tutorial_zh ...