c# - Set column width of Gridview inside rowdatabound event. -


i have following piece of code. did not define boundfields in gridview. retrieving data using sql queries in aspx.cs file instead. possible adjust width of each column 0, 1, 2? there ways can into? have tried lot of ways still not working. please help!

<asp:gridview id="surgicalgridview" runat="server"     captionalign="top" horizontalalign="justify"      datakeynames="id" onselectedindexchanged="surgicalgridview_selectedindexchanged"     tooltip="excel file download tool" cellpadding="4" forecolor="#333333"      gridlines="none" width="854px">       <rowstyle backcolor="#e3eaeb" />        <columns>        <asp:commandfield showselectbutton="true" selecttext="download"                 controlstyle-forecolor="blue"> <controlstyle forecolor="blue"></controlstyle>            </asp:commandfield>        </columns>      <footerstyle backcolor="#1c5e55" font-bold="true" forecolor="white" />      <pagerstyle backcolor="#666666" forecolor="white" horizontalalign="center" />      <selectedrowstyle backcolor="#c5bbaf" font-bold="true" forecolor="#333333" />      <headerstyle   backcolor="#1c5e55" font-bold="true" forecolor="white" />      <editrowstyle backcolor="#7c6f57" />      <alternatingrowstyle backcolor="white" />         <sortedascendingcellstyle backcolor="#f8fafa" />         <sortedascendingheaderstyle backcolor="#246b61" />         <sorteddescendingcellstyle backcolor="#d4dfe1" />         <sorteddescendingheaderstyle backcolor="#15524a" />     </asp:gridview>     <br /> 

you can on onrowdatabound event of gridview.

protected void surgicalgridview_rowdatabound(object o, gridviewroweventargs e) {                if (e.row.rowtype == datacontrolrowtype.datarow)     {          e.row.cells[0].width = new unit("200px");          e.row.cells[1].width = new unit("400px");          // , on     }  } 

add gridview markup

<asp:gridview ...............................         onrowdatabound="surgicalgridview_rowdatabound">    // add event , execute above code  </asp:gridview> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -