Solved

how to keep datagrid from growing in edit mode

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

22 Experts available now in Live!

Get 1:1 Help Now