C#GridView的 - 点击时使细胞在一列链接到另一个页面 [英] C# GridViews - Make the cells in one column link to another page when clicked
问题描述
我有一个从数据库填充一个网格视图。
I have a grid view which is populated from a database.
我需要它,以便每个特定列的单元格,点击时将通过链接到第二页,并通过单元格的文本值作为查询字符串(即链接的 http://mysite.com/page.aspx?CellText= 等等等等等等)。听起来很简单,但我知道我不能看着办吧!
I need to make it so that each of the cells in a particular column, when clicked will link through to a second page and pass the cell's text value as a query string (ie link to http://mysite.com/page.aspx?CellText='blah blah blah'). Sounds simple I know but I just can't figure it out!
这是我的网页看起来像此刻是什么:
This is what my page looks like at the moment:
<asp:GridView id="gdvTargets"
runat="server"
AutoGenerateEditButton="true"
OnRowEditing="gdvTargets_RowEdit"
OnRowUpdating="gdvTargets_RowUpdating"
OnRowUpdated="gdvTargets_RowUpdated"
OnRowCancelingEdit="gdvTargets_RowCancelingEdit"
cssClass="grid"
>
<HeaderStyle CssClass="GridHeader"></HeaderStyle>
和它背后我的C#code:
And my c# code behind it:
protected void Page_Load(object sender, EventArgs e)
{
year = Request.QueryString["YearSelector"];
targetType = Request.QueryString["TargetType"];
gdvTargets.DataSource = this.Ets.Api.Util.Db.GetDataTable("EXEC sp_getTargets " + year + ", " + targetType).Return;
gdvTargets.DataBind();
}
这导致它看起来像这样的表:
This results in a table which looks something like this:
ID System Target 1 Target 2 Target3 Target 4
0 ALL 10 20 15 10
2 Machine1 4 7 7 7
5 Xfgb 45 6 13 8 3
我想系统列可以点击并链接通过一个新的页面,但采取与它的系统的名称。希望这是有道理的!感谢您的帮助:D
I would like the system column to be clickable and link through to a new page but take the name of the system with it. Hope this makes sense! Thanks for your help :D
推荐答案
你可以做的是以下内容:
What you can do is the following:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Text = "<a href=''>" + e.Row.Cells[0].Text + "</a>";
}
你列索引替换0
Replace 0 by your column index
这篇关于C#GridView的 - 点击时使细胞在一列链接到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!