c# - set the height of the rows for rowDataBound method -


i have following codes:

protected void examplegridview_rowdatabound(object o, gridviewroweventargs e)     {         if (e.row.rowtype == datacontrolrowtype.datarow)         {             e.row.cells[0].width = new unit("150px");             e.row.cells[1].width = new unit("5px");             e.row.cells[2].width = new unit("150px");             e.row.cells[3].width = new unit("150px");             e.row.cells[4].width = new unit("150px");             e.row.cells[5].width = new unit("150px");             e.row.cells[6].width = new unit("150px");             // , on         }     } 

will possible set height of cells well? thanks!

you setting width @ rowdatabound() event. cannot that, try columns property before databind() occurs.

example

gridview1.cellpadding = 20; gridview1.rowstyle.height = 80; 

or can try sample

in aspx:

 <asp:gridview id="gridview1" onrowdatabound="gridview1_rowdatabound" autogeneratecolumns="false"         runat="server">         <columns>             <asp:boundfield datafield="catid" headertext="id" />             <asp:boundfield datafield="catname" headertext="name" />         </columns>     </asp:gridview> 

in .cs:

protected void page_load(object sender, eventargs e) {     list<category> _lstcategory = new list<category>{new category { catid = 1, catname = "cat1" },                                                          new category { catid=2,catname="cat2" }};     //gridview1.cellpadding = 20;     //gridview1.rowstyle.height = 80;     gridview1.datasource = _lstcategory;     gridview1.databind();  } public class category {     public int catid { get; set; }     public string catname { get; set; } } protected void gridview1_rowdatabound(object sender, gridviewroweventargs e) {     e.row.cells[1].width = 100;     e.row.cells[0].width = 1; } 

it works me.


Comments