Solved

how to keep datagrid from growing in edit mode

Posted on 2011-03-14
5
423 Views
Last Modified: 2012-08-14
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
Comment
Question by:mgmhicks
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 35135921
can you put your code for review (both pages)
0
 

Author Comment

by:mgmhicks
ID: 35137826
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
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 35143957
working on it, will reply soon
0
 
LVL 11

Accepted Solution

by:
Deepak Lakkad earned 250 total points
ID: 35144898
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
 

Author Closing Comment

by:mgmhicks
ID: 35151189
that worked thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question