datagrid edit column


When i click on edit,i am getting textboxes in grid to edit data.But their width is more and the grid is expanding .Is there a way to restrict the size of  editable text boxes.
<asp:DataGrid ID="gridLenders" runat="server" DataKeyField="id" BorderStyle="Ridge" GridLines="None" BorderWidth="2px" BorderColor="White" BackColor="White" CellPadding= "3" CellSpacing="1" AllowSorting="True" 
			  PagerStyle-HorizontalAlign = "Center" HorizontalAlign="Left" OnEditCommand="gridLenders_EditCommand" OnCancelCommand= "gridLenders_CancelCommand"  OnUpdateCommand="gridLenders_UpdateCommand"
			    OnDeleteCommand= "gridLenders_DeleteCommand" AutoGenerateColumns="false" width="96%" >
        <FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
        <HeaderStyle Font-Bold="True" ForeColor="#FFFFFF" 
       <FooterStyle BackColor="beige" />
        <asp:BoundColumn DataField="Id" HeaderText="ID"  Visible ="false" >
          <ItemStyle BackColor="graytext" />
          <HeaderStyle BackColor="graytext" />
          <asp:BoundColumn DataField="Lender" HeaderText="Lender">
          <ItemStyle BackColor="GhostWhite" />
          <asp:BoundColumn DataField="AccreditationId" HeaderText="AccreditationId">
          <ItemStyle BackColor="GhostWhite" />
          <asp:EditCommandColumn CancelText="Cancel" EditText="Edit"  
                         UpdateText="Update" HeaderText="Modify">
          <ItemStyle BackColor="GhostWhite" />
 <asp:ButtonColumn CommandName="Delete" HeaderText="Delete" Text="Delete">
          <ItemStyle BackColor="GhostWhite" />

Open in new window

Who is Participating?
lakshmidurgaConnect With a Mentor Author Commented:
Protected Sub Item_Created(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
    If e.Item.ItemType = ListItemType.EditItem Then

        Dim EditDescription As TextBox = CType(e.Item.Cells(0).Controls(0), TextBox)
        EditDescription.Width = Unit.Parse("500px")

    End If

End Sub

This is the solution
Try setting the bound column control style width for the column either through the designer or via code:

<asp:BoundColumn DataField="Id" HeaderText="ID"  Visible ="false" >
     <ControlStyle Width="100px" />
     <ItemStyle Width="100px" BackColor="graytext" />
     <HeaderStyle BackColor="graytext" />
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.