Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETC#4.0
Hello,
 
I have UnBound GridView - C# ASP.Net and I am refreshing this by query.
I have below code -
 
        SqlDataAdapter adp = new SqlDataAdapter("Select Entry_Date, Emp_Name, Qunatity, Comments From Activity_Master", SqlCon);
        System.Data.DataTable dt = new System.Data.DataTable();
        adp.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
 
I want to set Column width = 50 of "Comments" column and want Warp.
GridView1.Columns[3].ItemStyle.Width = 50;
      GridView1.Columns[3].ItemStyle.Wrap = true;
 
This gives me below error.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
 
How do resolve this. Please help.
Posted 3-May-12 20:42pm
Comments
AmitKumar89 at 4-May-12 3:17am
   
Can you provide us the html coding for the same grid.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Try setting your column width and wrapping style after binding the grid.
use this flow:
if(!IsPostBack){
   SqlDataAdapter adp = new SqlDataAdapter("Select Entry_Date, Emp_Name, Qunatity,             
        Comments From Activity_Master", SqlCon);
   System.Data.DataTable dt = new System.Data.DataTable();
   adp.Fill(dt);
   GridView1.DataSource = dt;
   GridView1.DataBind();
}
GridView1.Columns[3].ItemStyle.Width = 50;
GridView1.Columns[3].ItemStyle.Wrap = true;
 
All the best..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 718
1 OriginalGriff 421
2 Tadit Dash 355
3 sanket saxena 329
4 Peter Leow 193
0 Sergey Alexandrovich Kryukov 12,109
1 OriginalGriff 7,326
2 Peter Leow 5,003
3 Abhinav S 4,003
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 4 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid