在网格中添加超链接
我正在构建一个网络应用程序。这需要一个具有向下钻取功能的网格视图。 代码
使用系统 ; 使用系统集合; 使用系统配置; 使用系统数据; 使用 System.Linq; 使用系统.Web; 使用 System.Web.Security; 使用 System.Web.UI; 使用 System.Web.UI.HtmlControls; 使用 System.Web.UI.WebControls; 使用 System.Web.UI.WebControls.WebParts; 使用 System.Xml.Linq; 使用 System.Data.SqlClient; 使用 System.Net.Mail;
公共部分类 PcocDash :System.Web.UI.Page { 字符串 id = 字符串.Empty;
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtprocdash = new DataTable();
dtprocdash.Columns.Add("UOM");
dtprocdash.Columns.Add("Jan");
dtprocdash.Columns.Add("Feb");
dtprocdash.Columns.Add("Mar");
#region PRStatus 标头 DataRow dr = dtprocdash.NewRow(); dr["UOM"] = "";
dtprocdash.Rows.Add(dr);
endregion
区域 PO 数量
DataRow drprwithsla = dtprocdash.NewRow();
drprwithsla["UOM"] = "No";
SqlConnection co1 = new SqlConnection();
co1.ConnectionString = DataBaseOperation.GetConnectioString();
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = co1;
cmd1.CommandText = strQuery;
co1.Open();
//SqlDataReader rd = cmd.ExecuteReader();
SqlDataReader rd1;
rd1 = cmd1.ExecuteReader();
while (rd1.Read())
{
drprwithsla[2] = rd1["Jan"].ToString();
drprwithsla[3] = rd1["Feb"].ToString();
drprwithsla[4] = rd1["Mar"].ToString();
}
co1.Close();
dtprocdash.Rows.Add(drprwithsla);
protected void GridView1_RowDataBound(对象发送者,GridViewRowEventArgs e) if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.RowIndex == 0) { GridViewRow gvRow = e.Row; gvRow.Cells[0].Text = "公关状态"; gvRow.Cells[0].BackColor = System.Drawing.Color.Yellow; gvRow.Cells[0].HorizontalAlign = HorizontalAlign.Left; gvRow.Cells[0].Font.Italic = true; gvRow.Cells[0].Font.Bold = true;
}
if (e.Row.RowIndex == 1)
{
GridViewRow gvRow = e.Row;
gvRow.Cells[0].Text = "Total no of PR's";
gvRow.Cells[0].BackColor = System.Drawing.Color.Wheat;
gvRow.Cells[0].HorizontalAlign = HorizontalAlign.Right;
gvRow.Cells[0].Font.Italic = true;
}
问题
是我在 aspx 页面中创建了一个网格,并且所有列都已添加到 .cs 文件中。请有人帮帮我。如何在此页面添加超链接。我对 .net 真的很陌生。预先感谢您的任何回复
Iam building a web application. which requires a grid view with drill down .
Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;
public partial class PcocDash : System.Web.UI.Page
{
string id = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtprocdash = new DataTable();
dtprocdash.Columns.Add("UOM");
dtprocdash.Columns.Add("Jan");
dtprocdash.Columns.Add("Feb");
dtprocdash.Columns.Add("Mar");
#region PRStatus Header
DataRow dr = dtprocdash.NewRow();
dr["UOM"] = "";
dtprocdash.Rows.Add(dr);
endregion
region No of POs
DataRow drprwithsla = dtprocdash.NewRow();
drprwithsla["UOM"] = "No";
SqlConnection co1 = new SqlConnection();
co1.ConnectionString = DataBaseOperation.GetConnectioString();
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = co1;
cmd1.CommandText = strQuery;
co1.Open();
//SqlDataReader rd = cmd.ExecuteReader();
SqlDataReader rd1;
rd1 = cmd1.ExecuteReader();
while (rd1.Read())
{
drprwithsla[2] = rd1["Jan"].ToString();
drprwithsla[3] = rd1["Feb"].ToString();
drprwithsla[4] = rd1["Mar"].ToString();
}
co1.Close();
dtprocdash.Rows.Add(drprwithsla);
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
{
GridViewRow gvRow = e.Row;
gvRow.Cells[0].Text = "PR Status";
gvRow.Cells[0].BackColor = System.Drawing.Color.Yellow;
gvRow.Cells[0].HorizontalAlign = HorizontalAlign.Left;
gvRow.Cells[0].Font.Italic = true;
gvRow.Cells[0].Font.Bold = true;
}
if (e.Row.RowIndex == 1)
{
GridViewRow gvRow = e.Row;
gvRow.Cells[0].Text = "Total no of PR's";
gvRow.Cells[0].BackColor = System.Drawing.Color.Wheat;
gvRow.Cells[0].HorizontalAlign = HorizontalAlign.Right;
gvRow.Cells[0].Font.Italic = true;
}
}
The issue is i have created a grid in aspx page and all the columns have been added in .cs file . Please some one help me out . how to add hyperlink in this page . Iam really new to the .net . Thanks in advance for any response
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加超链接字段
在此处阅读更多信息:http://authors.aspalliance.com/ aspxtreme/webforms/controls/addinghyperlinkfieldstogridview.aspx
和此处:如何以编程方式动态填充 gridview 的绑定(超链接)列,然后使用该列的值作为 url?
Add a Hyperlink field
read more here :http://authors.aspalliance.com/aspxtreme/webforms/controls/addinghyperlinkfieldstogridview.aspx
and here: How do I programmatically fill a gridview's bound (hyperlink) column dynamically and then use the column's value as the url?
请尝试使用此代码在网格视图中添加超链接。
Windows 应用程序:
Web 应用程序:
Please try this code to add a hyperlink in grid view.
Windows Application:
WebApplication: