DetailsView fixed columns width - how to?

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
 
W

Walter Wang [MSFT]

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.
 
T

Tomasz

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
 
W

Walter Wang [MSFT]

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.
 
T

Tomasz

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
 
W

Walter Wang [MSFT]

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.
 
W

Walter Wang [MSFT]

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.
 
T

Tomasz

Thank you. This is a "good enough" solution. I do not why I did not think
about it!
Tomasz J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top