Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
setting default column width
posted

I'm having trouble setting default column width.

protected void Page_Load(object sender, EventArgs e)

{

 -- getting dataset from database here.

WebDataGrid1.DataSource = dsProdList;

WebDataGrid1.DataBind();

WebDataGrid1.Columns[1].Width = 150;  //this is my attempt to setting default column width

}

I am getting "Object reference not set to an instance of an object" error. I can only set default column if I have data source defined at design time. Can someone help me figure out how I can set the default column width?

Thank you in advance for all your help.

 

Parents
  • 14049
    Verified Answer
    Offline posted
    The columns in the Columns collection must be present at this point. So
    you'll need to either create them at design time, or add at run time.
    AutoGenerateColumns should be set to false in this case.
Reply Children
No Data