问题描述
大家好,
我正在使用带有自动显示列的Gridview来显示数据,我正在使用数据集绑定
网格作为数据集使我在下拉列表的选定索引上的交叉表/数据透视表数据发生了变化.
这是我正在使用的代码:
Hi Guys,
I am using Gridview with auto columns true to Display data, I am using Dataset to bind
Grid as Dataset gives me Crosstab/Pivot data on Dropdown''s selected Index changed.
Here is the code I am using:
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
fillGridview(Convert.ToInt32(ddl.SelectedValue));
bindHeader();
}
//===================//Bind GridColumns //=================
void bindHeader()
{
GridViewRow headerRow;
headerRow = gridDashboard.HeaderRow;
foreach (GridViewRow grdRow in gridDashboard.Rows)
{
int count = grdRow.Cells.Count;
int siteId=Convert.ToInt32(grdRow.Cells[4].Text);
for (int j = 0; j < count; j++)
{
if (j >= 5)
{
int id=Convert.ToInt32(grdRow.Cells[j].Text);
string headText =headerRow.Cells[j].Text.ToString();
string[] txtArray=headText.Split('-');
int stepId=Convert.ToInt32(txtArray[0]);
//headerRow.Cells[j].Text = txtArray[1].ToString();
string HeadName = txtArray[1].ToString();
LinkButton lb = new LinkButton();
lb.Style.Add("text-decoration","none");
if (id > 0)
{
string Details = getDashBoardSiteStepDetails(id);
lb.Text = Details;
}
else
{
lb.Text = " - ";
}
lb.CommandName = "HideColumn";
lb.CommandArgument = siteId.ToString() + "/" + stepId.ToString();
grdRow.Cells[j].Controls.Add(lb);
}
}
}
int cnt = headerRow.Cells.Count;
for (int j = 0; j
{
if (j >= 5)
{
string hdText = headerRow.Cells[j].Text.ToString();
string[] txtArray = hdText.Split('-');
// int stepId = Convert.ToInt32(txtArray[0]);
headerRow.Cells[j].Text = txtArray[1].ToString();
}
}
在上面的代码中,我试图在每个单元格中动态添加一个按钮,并且文本中的按钮具有该单元格的文本.效果很好,但是当我单击创建的链接按钮时,链接按钮消失,并且显示单元格的原始文本.
请帮忙.我还想创建这些链接按钮的onclick.
谢谢
In the above code, I am trying to add a button dynamically in each cell and button in text has text of that cell. It works great but when I click the link button created, link buttons disappear and the original text of the cell displays.
Please help. I also want to create onclick of these link buttons.
Thanks
推荐答案
这篇关于在自动生成的列为true的动态生成的gridview中添加按钮的问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!