Results 1 to 4 of 4

Thread: Datagrid textbox width (edit mode)***resolved****

  1. #1

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228

    Datagrid textbox width (edit mode)***resolved****

    I have a datagrid that has Edit, Update,Cancel capability (the custom column). What I need is to specify the width of the textbox when I choose edit. As it stands the grid triples in size because of the size of the input fields. I tried the following code
    VB Code:
    1. Public Sub DataGrid_Edit(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
    2. dgBeach.EditItemIndex = E.Item.ItemIndex
    3. BindData()
    4. E.Item.Cells(3).Width = System.Web.UI.WebControls.Unit.Pixel(25)
    5. End Sub

    I also tried with the pixel code in different spots but no difference can be seen.
    Any ideas?
    Last edited by Halon; Nov 26th, 2002 at 06:08 PM.
    Soylent Green tastes like chicken

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Try e.Item.Attributes.Add("Style", "Width: 25px;")
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    Nope ... can't figure out exactly where it is creating these default text boxes when you click on edit. Do I have to make each column a template column maybe?
    Soylent Green tastes like chicken

  4. #4

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    OK I ended up going with template columns

    In my datagrid update code
    VB Code:
    1. Dim Cash As Integer
    2. Cash = CType(E.Item.FindControl("txtcash"), TextBox).Text
    In the html for the datagrid
    VB Code:
    1. <asp:TemplateColumn HeaderText="Cash">
    2. <ItemTemplate>
    3. <asp:Label runat="server" Text='<%# DataBinder.Eval Container, "DataItem.Cash", "{0:$#,###.##}") %>'>
    4. </asp:Label>
    5. </ItemTemplate>
    6. <EditItemTemplate>
    7. <asp:TextBox runat="server" id="txtcash" columns="3" Text='<%# DataBinder.Eval(Container, "DataItem.Cash") %>'>
    8. </asp:TextBox>
    9. </EditItemTemplate>
    10. </asp:TemplateColumn>

    It now allowed me to set the column width for the textbox

    yeehaww i guess
    Soylent Green tastes like chicken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width