Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to expand/Collapse a row in gridview. I have added a row dynamically under each static row in GridView in rowdatabound, But on postback it displays the dynamically created row after each static row without any value.Suppose we have 2 static rows dynamically we created 2 more rows on each row, after postback it displays 2 rows 1 the static row and other one the dynamically created row without any value 2nd static row is missing.

Please help me in creating rows dynamically.
Posted
Updated 9-Feb-18 23:10pm
Comments
Kschuler 13-Aug-10 10:05am    
Please edit your question and include your code so people can better help you.
Sandeep Mewara 13-Aug-10 11:53am    
Add some code snippet to explain it.

1 solution

what is your exact purpose for creating dynamical row? To display some picture?
as I know it is easy to dynamially create the row, but not easy to maintainance. I have similar experience. My purpose of creating dynamical row is to insert a blank row without height below some special rows to highlight them, however, it will completely change after postback. My solution is changing the style of the row instead of inserting a new row.


C++
private void InsertSummaryRow(GridView gv,  int rowIndex,int colSpan, int HLfontSize)
 {

     //this is just an example of how to insert the dynamical row. HLfontSize is the font size of the label

     Label Summary0 = new Label();

    Summary0.Text = "Summary:";
     Summary0.Font.Size = HLfontSize;  Summary0.ForeColor = System.Drawing.Color.FromName("MediumBlue"); Summary0.Height = Unit.Parse("20px");

     GridViewRow tr = new GridViewRow(0, 0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
     TableCell cel = new TableCell();
     cel.ColumnSpan = colSpan;
     cel.Style.Add("border-bottom", "blue 3px solid");  //style of the row
     cel.Style.Add("white-space", "nowrap"); //style of the row
     cel.Controls.Add(Summary0);
     tr.Cells.Add(cel);

     gv.Controls[0].Controls.AddAt(rowIndex, tr);

 }
 
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