• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

how to keep datagrid from growing in edit mode

I have a grid actually 2 datagrids.  Each grid resides on a different page from each other.  When I click the edit link on a row, the gridrow goes to edit mode and the text fields are staying the same size as they are in none edit mode.  However the grid same setup, on the other page when I click edit the grid grows horizontally and the fields arent the same size.  Cant figure out how to stop it.

thanks
0
mgmhicks
Asked:
mgmhicks
  • 3
  • 2
1 Solution
 
Deepak LakkadCommented:
can you put your code for review (both pages)
0
 
mgmhicksAuthor Commented:
the first one is the one that works correctly.  The 2nd one grows horizontally in edit mode.

Here is the edit code for

 Private Sub gvCategories_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvCategories.RowEditing
        gvCategories.EditIndex = e.NewEditIndex
        gvCategories.DataSource = dsCategories.Tables(0)
        gvCategories.DataBind()
    End Sub

 Private Sub gvItems_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvItems.RowEditing
        gvItems.EditIndex = e.NewEditIndex
        gvItems.DataSource = dsItems.Tables(0)
        gvItems.DataBind()
    End Sub
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Companion.master" CodeBehind="InspectionCategories.aspx.vb" Inherits="CrystalReportsTest.InspectionGroups" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

   <script language="javascript" type="text/javascript" >
   
   
   </script>
   

        <asp:Label ID="Label2" runat="server" Text="Inspection Categories" 
            Font-Size="X-Large" ForeColor="Red" Font-Bold="True"></asp:Label>&nbsp;<br />
        <br />
        &nbsp; 
    
    
    <table style="width: 88%">
        <tr>
            <td align="left" valign="bottom">
                <asp:Label ID="Label7" runat="server" Text="Location Selection:"></asp:Label>
                <asp:DropDownList ID="ddLocations" runat="server" AutoPostBack="True" 
                    Height="25px">
                </asp:DropDownList>
            </td>
        </tr>
    </table>
    <p>
        <asp:Label ID="lblChanged" runat="server" Text="Label" Visible="False"></asp:Label>
    </p>
      <div id ="divCategories">
        <asp:GridView ID="gvCategories" runat="server" AutoGenerateColumns="False" 
            Width="744px" AutoGenerateDeleteButton="True" 
            AutoGenerateEditButton="True" BorderColor="Black" BorderStyle="Solid" 
              BorderWidth="5px">
            <Columns> 
                <asp:BoundField DataField="ID" ReadOnly="True" ShowHeader="False" 
                    Visible="False" >
                <ItemStyle Wrap="False" />
                </asp:BoundField>
                <asp:BoundField DataField="short_name" HeaderText="Short Name">
                <ItemStyle Width="200px" Wrap="False" HorizontalAlign="Left" />
                </asp:BoundField>
                <asp:BoundField DataField="long_name" HeaderText="Long Name" >
                <ItemStyle HorizontalAlign="Left" />
                </asp:BoundField>
                <asp:BoundField DataField="Color" HeaderText="Color" />
                <asp:CheckBoxField DataField="Active" HeaderText="Active" >
                <ItemStyle Wrap="False" />
                </asp:CheckBoxField>
            </Columns>
        </asp:GridView>
</div>
<p></p>


<table style="border-color: #000000; border-style: solid; width: 741px; " 
            id="TblAdd" >
        <tr>
            <td align="left" style="text-align: left; font-weight: bold;">
                Short Name</td>
            <td style="text-align: left; width: 387px; font-weight: bold;">
                Long Name</td>
            <td style="text-align: left; font-weight: bold">
                Color</td>
            <td style="font-weight: bold">
                Active</td>
        </tr>
        <tr>
            <td align="left" style="text-align: left;" valign="top">
                <asp:TextBox ID="txtNewShortName" runat="server" MaxLength="25" Width="182px"></asp:TextBox>
            </td>
            <td style="text-align: left; width: 387px;">
                <asp:TextBox ID="txtNewLongName" runat="server" TextMode="MultiLine" 
                    Width="291px"></asp:TextBox>
            </td>
            <td>
                <asp:DropDownList ID="ddColors" runat="server" AutoPostBack="True" CausesValidation="True" 
                   
                    >
                </asp:DropDownList>
                <asp:Panel ID="Panel1" runat="server" style="height: 16px">
                </asp:Panel>
            </td>
            <td valign="top">
                <asp:CheckBox ID="chkActive" runat="server" Text=" " />
            </td>
        </tr>
        <tr>
            <td style="text-align: center;" valign="top" colspan="4">
                &nbsp;</td>
        </tr>
        <tr>
            <td style="text-align: center;" valign="top" colspan="4">
&nbsp;&nbsp;&nbsp;&nbsp;
                                
            </td>
        </tr>
    </table>

<p>
        &nbsp;</p> 
   
        &nbsp;&nbsp;<asp:Button ID="btnAdd" runat="server" Height="30px" 
        Text="Add Category" Width="135px" />
    &nbsp;&nbsp;
        <asp:Button ID="btnCancel" runat="server" Height="30px" Text="Cancel" 
            Width="135px" />
   
    <p>
        &nbsp;</p>
<script language="javascript" type="text/javascript">
// <!CDATA[

function btnAdd_onclick() {

}
function ChangeColor()
{
    var element = document.getElementById('ctl00_ContentPlaceHolder1_ddColors')
    debugger
    var myColor = document.getElementById('ctl00_ContentPlaceHolder1_panel').innertext

}
function btnAdd_onclick() {

}

// ]]>
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>

Open in new window

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Companion.master" CodeBehind="InspectionItems.aspx.vb" Inherits="CrystalReportsTest.InspectionItems" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Label ID="Label2" runat="server" Text="Inspection Items" 
            Font-Size="X-Large" ForeColor="Red" Font-Bold="True"></asp:Label>
    <br />
    <br />
    <br />
    <table style="width: 88%">
        <tr>
            <td style="border: thin none #000000; text-align: left;">
                <asp:Label ID="Label7" runat="server" Text="Location Selection:"></asp:Label>
&nbsp;<asp:DropDownList ID="ddLocations" runat="server" AutoPostBack="True">
                </asp:DropDownList>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblChanged" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
    </table>
    
    <br />
    <div>
    <asp:GridView ID="gvItems" runat="server" AutoGenerateColumns="False" 
         Width="744px" AutoGenerateDeleteButton="True" 
    AutoGenerateEditButton="True" BorderColor="Black" BorderStyle="Solid" 
        BorderWidth="5px" AllowPaging="True">
                      
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" Visible="False" ReadOnly="True" >
            <ItemStyle Wrap="False" HorizontalAlign="Left" Width="10px" />
            </asp:BoundField>
            <asp:BoundField DataField="Item" HeaderText="Item" >
            <ItemStyle Width="50px" HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="Descrip" HeaderText="Description" >
            <ItemStyle Width="300px" HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="Cost" HeaderText="Cost" DataFormatString="{0:C}" >
            <ItemStyle Width="25px" HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="Price" HeaderText="Price" DataFormatString="{0:C}" >
            <ItemStyle Width="25px" HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="category" HeaderText="Category" >
            <ItemStyle Width="10px" HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="Sub_Category" HeaderText="Sub Category" >
            <ItemStyle Width="10px" HorizontalAlign="Left" />
            </asp:BoundField>
        </Columns>
        
    </asp:GridView>
    </div>
    <br />
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>

Open in new window

0
 
Deepak LakkadCommented:
working on it, will reply soon
0
 
Deepak LakkadCommented:
Hi

Use <asp:TemplateField> in place of <asp:BoundField>

Your code is

<asp:BoundField DataField="ItemName" HeaderText="Item" >
          <ItemStyle Width="100px" HorizontalAlign="Left" /> 
</asp:BoundField>

Open in new window


replace it as under

 <asp:TemplateField HeaderText="Item Name">
                    <ItemTemplate>
                        <asp:Label ID="lblItemName" runat="server" Text='<%# Eval("ItemName") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtItemName" runat="server" width="100px" Text='<%# Eval("ItemName") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>

Open in new window



This will restrict width of column

- Deepak Lakkad
0
 
mgmhicksAuthor Commented:
that worked thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now