DetailsView edit and insert row widths

W

William LaMartin

Is there a way to increase the width of the text boxes for the DetailsView
in edit or insert mode? When I put the control in either edit or insert
mode, the text boxes to type the new text are always much smaller than the
available space in the row.
 
W

Wiktor Zychla [C# MVP]

Is there a way to increase the width of the text boxes for the DetailsView
in edit or insert mode? When I put the control in either edit or insert
mode, the text boxes to type the new text are always much smaller than the
available space in the row.

I do not know an obvious answer to that. However, there are two
possibilities:

a) use TemplateFields instead of BoundFields. this way you precisely define
how the edit/insert template looks like so you easily add required
attributes to TextBoxes that you place in templates (I prefer this techique)
b) write a DataBound event handler with a foreach loop for DetailsView's
rows. inside a loop you check if the row contains a TextBox and set
TextBox's width to 100% (I didn't exactly tested that in your scenario but I
use this technique constantly to tweak DetailsView's apperance in other
cases, for example to remove/disable buttons of a CommandField).

If another possibility exists I would be glad to learn it.

Regards,
Wiktor Zychla
 
W

William LaMartin

Changing to template fields worked fine since there is a width attribute.

Thanks
 
Joined
Nov 25, 2008
Messages
1
Reaction score
0
For what it's worth two years later...

You don't need to change this to a TemplateField. You can use the ControlStyle and the ItemStyle to set the Width.

<asp:BoundField DataField="MyField" HeaderText="My Field" SortExpression="MyField" >
<ControlStyle Width="200px" />
<ItemStyle Width="200px" />
</asp:BoundField>

As you can probably guess, the ItemStyle will change the width in view mode and the ControlStyle will change the width of the textbox in Edit mode.

I hope this saves some future searcher the small headache of converting all their fields to do this.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top