Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to keep datagrid from growing in edit mode

Posted on 2011-03-14
5
420 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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.

839 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