在网格中添加超链接

时间:2011-01-03 10:30:26

标签: c# gridview hyperlink

我正在构建一个Web应用程序。这需要一个向下钻取的网格视图。 代码

使用System; 使用System.Collections; 使用System.Configuration; 使用System.Data; 使用System.Linq; 使用System.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;

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标题        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(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] .Horizo​​ntalAlign = Horizo​​ntalAlign.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。提前感谢您的回复

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

请尝试使用此代码在网格视图中添加超链接。

Windows应用程序:

DataGridViewLinkColumn View = new DataGridViewLinkColumn();
View.HeaderText = "";
View.Width = 30;
View.Name = "View";
View.Text = "Print";
gv_CRWS_details.Columns.Insert(0, View);

<强> WebApplication的:

GridViewLinkColumn View = new GridViewLinkColumn();
    View.HeaderText = "";
    View.Width = 30;
    View.Name = "View";
    View.Text = "Print";
    gv_CRWS_details.Columns.Insert(0, View);