Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DetailsView control width shrinks when click "Edit"

Status
Not open for further replies.

bubberz

Programmer
Dec 23, 2004
117
US
I have a DetailsView control, and it has several fields that may contain over 100 characters. Once I click "Edit" for the control, the field shrinks to almost 15-20 characters. Is there a way around this so the initial width of the field stays the same even when I click edit so the user can view the whole field value rather than just a small portion?
The DataGrid control seems to do the same thing.
Thanks!
 
You can manually set column widths in the datagrid by doing something like:
Code:
datagrid1.Columns(0).ItemStyle.Width.Pixel(150)
so you could do a similar thing on the ItemCreated event for each column/textbox.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Thanks ca8msm for the fast response. Which declaration would this go under? Init? ModeChanging? ItemInserting?
Thanks again!
 
Sorry....just saw I should put it under ItemCreated Event
Thanks again!
 
I tried:
Private Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.SelectedRow.Width.Equals(600)
End Sub

...but this keeps giving me "Object reference not set to an instance of an object" when I click on "Edit"

Any other suggestions? Am I doing something wrong?
 
You should use the ItemCreated event like I said in my original post and set either the column width of the datagrid (you are trying to set the row width in you attempt above) or use the FindControl method to find the Textbox and change the width of that.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
ca8msm,

I don't have a [DetailsView2.Columns(0)....] namespace

I've tried:
DetailsView2.Fields(0).ItemStyle.Width.Type.Pixel.Equals(100%)
...and...
DetailsView2.Fields(0).ItemStyle.Width.Type.Pixel.Equals(500)
...and neither make the field stay the same width as when the user views the record.
Thanks for continuing to help!
 
The reason that I suggested using the ItemCreated event was that from there you can modify the actual items that are created so you could modify the actual item width. Something like to following will probably work:
Code:
e.Item.Cells[0].Width = Unit.Pixel(50)
or if not you can use the FindControl method (which I mentioned earlier) to find the Textbox control and set the width of the textbox.



----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Ah ha....I had to go via the Source view of the .aspx page and add the <ASP:BoundField> attribute:

ControlStyle-Width="800"

Thanks for the suggestions!
 
Of course now, I can't get it to wrap. I've got the attribute in there:
<asp:BoundField HeaderText="Work Scope" DataField="Work Scope" SortExpression="Work Scope" ItemStyle-Wrap=true>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top