Problem in Adding Button in Dynamically created Gridview with Auto Generated Columns True
Posted
by Anuj Koundal
on Stack Overflow
See other posts from Stack Overflow
or by Anuj Koundal
Published on 2009-12-03T13:47:53Z
Indexed on
2010/05/09
5:38 UTC
Read the original article
Hit count: 397
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 slected 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();
}
}
In above code I am trying to add button dynamically in each cell and button in text have 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
© Stack Overflow or respective owner