【问题标题】:To add hyperlink in grid在网格中添加超链接
【发布时间】:2011-06-02 19:01:13
【问题描述】:

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

使用系统; 使用 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;

公共部分类 PcocDash : System.Web.UI.Page { 字符串 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(); 博士["UOM"] = "";

    dtprocdash.Rows.Add(dr);

结束区域

地区采购订单数

    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) { 如果(e.Row.RowIndex == 0) { GridViewRow gvRow = e.Row; gvRow.Cells[0].Text = "公关状态"; 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 真的很陌生。提前感谢您的任何回复

【问题讨论】:

    标签: c# gridview hyperlink


    【解决方案1】:
    【解决方案2】:

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

    Windows 应用程序:

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

    网络应用程序:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 2014-05-13
      • 1970-01-01
      • 2016-12-28
      • 2019-05-17
      • 2013-08-27
      相关资源
      最近更新 更多