DetailsView fixed columns width - how to?

  • Thread starter Thread starter Tomasz
  • Start date Start date
T

Tomasz

Hello Developers,

DetailsView control, typically, has two columns: names and values.
How do I define either fixed or minimum width of those columns?
I have tried modifying EditRowStyle and RowStyle width, but with no good
results.
I would appreciate any hints.

Thank you,

Tomasz
 
Hi Tomasz,

You can set the DetailsView's width to a fixed value and use
FieldHeaderStyle-Width attribute to set the "name" field's width; the
"value" field's width can be determined by them:

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="ObjectDataSource1"
Height="50px" Width="800px" FieldHeaderStyle-Width="400px">


Let me know if this works on your side.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Walter,



Thank you for your response.



Is there any way I can set fixed "value column" width, while allowing the
"name column" change its width dynamically?



Typically, you do not know the "name column" size but you also do not want
"name labels" wrap, and you want to leave enough, arbitrary specified space
for the user input - the "value column" size. I think this is the most
common scenario.

I am sure many other developers already came across this problem.



Respectfully,



Tomasz
 
Hi Tomasz,

To do that, set either field's ItemStyle-Width attribute. For example:

<asp:DetailsView...
<Fields>
<asp:BoundField ItemStyle-Width="400px" ...


Since the fields are displayed in one table with two columns, the last <td>
that has a width setting will determine the entire column's width.


Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks. I was affraid there was no better way to solve this problem.
It is especially inconvienient with templates, since the same width should
be set for all three (EditItemTemplate, InsertItemTemplate, ItemTemplate),
which decreases code maintainability.

Tomasz
 
Hi Tomasz,

For TemplateField, I believe you also only need to set the ItemStyle-Width
once for the TemplateField element:

<asp:TemplateField ItemStyle-Width="500px">

Like I described in my previous reply, you only need to set this on one of
your field. By the way, please note applying this attribute on the
CommandField will not work since the CommandField spans two columns.

Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Tomasz,

What do you think about above suggestion?

Please feel free to let me know if there's anything else I can help.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you. This is a "good enough" solution. I do not why I did not think
about it!
Tomasz J
 
Back
Top