Click here to Skip to main content
15,896,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
DataTable Stb = new DataTable("SearchTB");
            Stb.Columns.Add("SCode", typeof(string));
            Stb.Columns.Add("SName", typeof(string));
            OdbcCommand cmd = new OdbcCommand("SELECT  ItemCode, Description FROM ITEM", MainClass.Conn);
            OdbcDataAdapter da = new OdbcDataAdapter(cmd);
            da.Fill(Stb);
            da.Dispose();
            gvSearch.DataSource = Stb;

after executing the above code it's generate two blank columns i want to add records(ItemCode/Description) to predefined columns(SCode/SName) And Want To re size the data grid view columns width

how to do this..?
Posted
Updated 23-Oct-12 1:46am
v2
Comments
[no name] 23-Oct-12 4:24am    
Could you please be more specific about your question?

1 solution

you can use row data bound event of grid view to re-size column width.
use following code :

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
(
   if (e.Row.RowType == DataControlRowType.Header)
   {
       e.Row.Cells[1].Width = 100;
       e.Row.Cells[2].Width = 100;
   }
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
       e.Row.Cells[1].Width = 100;
       e.Row.Cells[2].Width = 100;
   }
}
 
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