Hi Sam,
Thanks very much for your feedback.
I am glad you find your problem. For your further problems, I will explain
it one-by-one to you:
1. For DataGrid control, it will render as <table> html element at client
side.
If you set ItemStyle.Width property, you specify all the items' width to
certain value. While, for datagrid, each item is just a row, that is <td>
element at client side.
So it will render a "width" attribute for each td(Except the first row,
because the first row is the datagrid's header) as:
<tr>
<td style="width:300px;">1</td><td>1</td><td>New Hire - Job not
specified</td><td>10</td><td>0</td>
</tr>
While the first row will have no "width" attribute, like:
<tr>
<td>ID</td><td>job_id</td><td>job_desc</td><td>max_lvl</td><td>enum</td>
</tr>
For client html behavior, the "unspecified" value <td> will adjust it width
as other <td>s, so the entire column will have the same 300px width.
While if you specify HeaderStyle's Width to 300px, the render result is
complete reverse. The first row(Header row) will have "width" attribute
with "300px", other rows have no "width" attribute.
In this situation, the other rows will follow the first row(Header row)'s
width, so the entire column will behave have the same 300px width.
2 and 3. If you see in MSDN, you will see that DataGrid.Width property is
inherited from WebControl(Base class). It will add a "width" attribute in
the "Style" attribute for <table> element at client.
If you specify DataGrid.Width, it will specify the whole width of the
entire datagrid(That is <table> element at client side). So if you use:
DataGrid1.Width = Web.UI.WebControls.Unit.Pixel(3000)
It will render as(I have omit all the other attibutes):
<table id="DataGrid1" style="width:3000px;">
So the entire <table>'s width will be 3000px.
But for:
datagrid1.width = col1 width + col2 width + col3 width + ......
I think what you want to do is adding all the columns' width and specify to
the datagrid. Actually, default, there will be no Width property value for
each column. That is DataGridColumn.ItemStyle.Width property will be 0.
Your code will specify 0 for the datagrid, so it will not work correctly.
===========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.