Solved

how to keep datagrid from growing in edit mode

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now