【发布时间】:2013-09-03 12:25:30
【问题描述】:
我要显示n网格,n是可变的,那我不知道我会有多少网格。
我的问题是,我必须用 Visible false 来初始化这个网格,当点击一个按钮时会显示该按钮的特定网格,那么我怎样才能将一个按钮链接到一个网格视图?
我生成网格的代码:
foreach (List<DataRow> lst in grids)
{
dt = lst.CopyToDataTable();
GridView grv = new GridView();
grv.AlternatingRowStyle.BackColor = System.Drawing.Color.FromName("#cccccc");
grv.HeaderStyle.BackColor = System.Drawing.Color.Gray;
grv.ID = "grid_view"+i;
grv.Visible = false;
grv.DataSource = dt;
grv.DataBind();
Label lblBlankLines = new Label();
lblBlankLines.Text = "<br /><br />";
Label lblTipo = new Label();
string tipoOcorrencia = lst[0]["DESC_OCORRENCIA"].ToString();
tipoOcorrencia = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tipoOcorrencia);
int quantidade = lst.Count;
lblTipo.Text = tipoOcorrencia + ": " + quantidade;
LinkButton lkBtn = new LinkButton();
lkBtn.ID = "link_button"+i;
lkBtn.Text = "+";
place_grids.Controls.Add(lblBlankLines);
place_grids.Controls.Add(lkBtn);
place_grids.Controls.Add(lblTipo);
place_grids.Controls.Add(grv);
place_grids.DataBind();
i++;
}
提前致谢。
【问题讨论】:
-
你在哪里添加链接按钮?
-
我要补充,但我不知道正确的做法。
-
一次只能绑定一个网格。当您单击按钮时,它将根据索引值绑定新网格。
标签: c# asp.net gridview dynamic-data