Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:




C#
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 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
Posted
Updated 5-Dec-09 16:44pm
v4

1 solution

Try enabling viewstate on the linkbutton, if you haven't.

alternately, recreate the button on the postback.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900