Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a grid in form in that I am binding values to the grid from DB consisting of four columns in that I had set size for the columns width. how do I make it possible?
Posted

C#
protected void Grid1_RowDataBound(object sender, Obout.Grid.GridRowEventArgs e)
    {
        if (e.Row.RowType == GridRowType.DataRow)
        {
           e.Row.Cells[1].Width = (what ever you want(int value only));


        }


}
 
Share this answer
 
Comments
riodejenris14 14-Jun-13 5:10am    
Hi Nirav there is no event rowdatabound for my grid view in property...
Nirav Prabtani 14-Jun-13 5:13am    
Hi, muhammed riyaaz
may i know which grid you are using???
riodejenris14 14-Jun-13 5:17am    
DataGrid from tool bar menu, Nirav.
Nirav Prabtani 14-Jun-13 5:22am    
just click on grid events from solution explorer after clicking F4 for grid properties
riodejenris14 14-Jun-13 5:28am    
yes Nirav what you said is correct but it is for aspx page not for windows application...
Hey You can do like this :
C#
      <asp:boundfield xmlns:asp="#unknown">
            DataField="Column_Name" HeaderText="Column_Name" >
<HeaderStyle Width="180px">

<itemstyle width="180px"></itemstyle>
        </asp:boundfield>
 
Share this answer
 
Comments
riodejenris14 6-Jun-13 9:28am    
for windows form application!!!
Try:

C#
foreach (DataGridViewColumn c in dataGridView1.Columns)
           {
               //the if statement depents on how you can search your data
               if (c.Name == "TheNameOfTheColumn")
               {
                   c.Width = 250;
               }
               if (c.HeaderText == "TheHeaderTextYouWant")
               {
                   c.Width = 500;
               }
           }
 
Share this answer
 
Comments
nandakishoreroyal 12-Jun-13 5:17am    
<itemstyle width="180px">

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