【发布时间】:2014-02-14 20:56:27
【问题描述】:
我正在使用 SQL 数据源生成 Gridview。数据源有一个使用 PIVOT 生成基于日期的列名的存储过程。我想让每个单元格都可点击(基于列中的文本),但找不到列名。
我尝试了一些方法,例如检查 Row[0]。理想情况下,我想将基于行的第一列和列标题的单元格的值传递给更新面板,但首先我需要知道我正在创建的单元格的列标题文本是什么。
if (e.Row.RowType != DataControlRowType.Header)
{
string item = e.Row.Cells[0].Text;
string column;
for (int j = 0; j < e.Row.Cells.Count; j++)
{
column = GridView1.HeaderRow.Cells[j].Text;
if (j >= 3)
{
e.Row.Cells[j].Font.Italic = true;
e.Row.Cells[j].Text = e.Row.Cells[j].Text.Replace(".00", "");
//if (GridView1.HeaderRow.Cells[j].Text.Substring(0,3) == "SKU")
//{
e.Row.Cells[j].Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
e.Row.Cells[j].Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.Cells[j].ToolTip = "Click to select cell";
e.Row.Cells[j].Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
//}
【问题讨论】:
-
你用哪一个事件来做这个???
-
OnRowDataBound (GridView1_DataBound(object sender, GridViewRowEventArgs e))