troubleshooting Question

Gridview expands beyond page width in Edit Mode

Avatar of dgore1
dgore1 asked on
.NET ProgrammingASP.NETVisual Basic.NET
4 Comments1 Solution1483 ViewsLast Modified:
I have been wrestling with the gridview control extending beyond the right side of the page for about 2 months now.  I have cut down on names of fields, made them multi line etc. but still long gridviews go off the page.  Is there any way when a gridview goes into edit mode to restrict the width of a column so that it stays within the page?

I have attached a sample aspx, I can also give the entire page is necessray, just for review.

thanks,
dale

<fieldset>
 
<legend>
Selected Key Details
</legend>
<div>
 
<asp:GridView id="GridView4" runat="server" Width="100%" Height="100%" 
        ForeColor="#333333" DataSourceID="SqlDataSource7" EmptyDataText="There are no data records to display." 
        DataKeyNames="KeyID" CellPadding="4" AutoGenerateColumns="False" 
        AllowPaging="True" AllowSorting="True" PageSize="6">
<AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
 
<EditRowStyle BackColor="#999999"></EditRowStyle>
 
    <Columns>
        <asp:TemplateField ShowHeader="False">
            <EditItemTemplate>
                <asp:Button ID="Button1" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False" 
                    CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Button ID="Button2" runat="server" CausesValidation="False" 
                    CommandName="Select" Text="Select" />
                <asp:Button ID="Button3" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete" />
                <asp:Button ID="Button1" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="KeyID" HeaderText="Key ID" InsertVisible="False" 
            ReadOnly="True" SortExpression="KeyID" />
        <asp:BoundField DataField="FIFullKey_FIFacilityInfo" 
            HeaderText="Site" 
            SortExpression="FIFullKey_FIFacilityInfo" />
        <asp:BoundField DataField="KeyCode" HeaderText="Key Code" 
            SortExpression="KeyCode" />
        <asp:BoundField DataField="Accesses" HeaderText="Access" 
            SortExpression="Accesses" />
        <asp:BoundField DataField="KeyRingID" HeaderText="Key Ring ID" 
            SortExpression="KeyRingID" />
        <asp:CheckBoxField DataField="FileKey" HeaderText="File Key" 
            SortExpression="FileKey" ReadOnly="True" />
        <asp:CheckBoxField DataField="Active" HeaderText="Act" 
            SortExpression="Active" ReadOnly="True" />
        <asp:CheckBoxField DataField="Restricted" HeaderText="Res" 
            SortExpression="Restricted" ReadOnly="True" />
        <asp:CheckBoxField DataField="Emergency" HeaderText="Emerg" 
            SortExpression="Emergency" ReadOnly="True" />
        <asp:BoundField DataField="HookID" HeaderText="Hook ID" 
            SortExpression="HookID" />
        <asp:BoundField DataField="BrandID" HeaderText="Brand ID" 
            SortExpression="BrandID" />
        <asp:BoundField DataField="ManufacturerKeyCode" 
            HeaderText="Manuf Key Code" SortExpression="ManufacturerKeyCode" />
        <asp:BoundField DataField="KeyWayPinningCode" HeaderText="KeyWay Pinning Code" 
            SortExpression="KeyWayPinningCode" />
        <asp:BoundField DataField="KeyCutCode" HeaderText="Key Cut Code" 
            SortExpression="KeyCutCode" />
        <asp:BoundField DataField="KeysComments" HeaderText="Keys Comments" 
            SortExpression="KeysComments" />
    </Columns>
 
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
 
<HeaderStyle HorizontalAlign="Left" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
 
<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"></PagerStyle>
 
<RowStyle BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
 
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"></SelectedRowStyle>
 
</asp:GridView> 
 
<asp:SqlDataSource ID="SqlDataSource7" runat="server" 
                 ConnectionString="<%$ ConnectionStrings:LockandKeyConnectionString %>" 
                 SelectCommand="SELECT KeyID, FIFullKey_FIFacilityInfo, KeyCode, Accesses, KeyRingID, ISNULL(FileKey, 0) AS FileKey, ISNULL(Active, 0) AS Active, ISNULL(Restricted, 0) AS Restricted, ISNULL(Emergency, 0) AS Emergency, HookID, BrandID, ManufacturerKeyCode, KeyWayPinningCode, KeyCutCode, KeysComments FROM dbo.Keys AS L WHERE (KeyCode = @KeyCode)" 
        DeleteCommand="DELETE FROM [Keys] WHERE [KeyID] = @KeyID" 
        InsertCommand="INSERT INTO [Keys] ([FIFullKey_FIFacilityInfo], [KeyCode], [Accesses], [KeyRingID], [FileKey], [Active], [Restricted], [Emergency], [HookID], [BrandID], [ManufacturerKeyCode], [KeyWayPinningCode], [KeyCutCode], [KeysComments]) VALUES (@FIFullKey_FIFacilityInfo, @KeyCode, @Accesses, @KeyRingID, @FileKey, @Active, @Restricted, @Emergency, @HookID, @BrandID, @ManufacturerKeyCode, @KeyWayPinningCode, @KeyCutCode, @KeysComments)" 
        
        
        UpdateCommand="UPDATE [Keys] SET [FIFullKey_FIFacilityInfo] = @FIFullKey_FIFacilityInfo, [KeyCode] = @KeyCode, [Accesses] = @Accesses, [KeyRingID] = @KeyRingID, [FileKey] = @FileKey, [Active] = @Active, [Restricted] = @Restricted, [Emergency] = @Emergency, [HookID] = @HookID, [BrandID] = @BrandID, [ManufacturerKeyCode] = @ManufacturerKeyCode, [KeyWayPinningCode] = @KeyWayPinningCode, [KeyCutCode] = @KeyCutCode, [KeysComments] = @KeysComments WHERE [KeyID] = @KeyID">
                 <SelectParameters>
                     <asp:ControlParameter ControlID="GridView3" Name="KeyCode" 
                         PropertyName="SelectedDataKey.Values(KeyCode)" Type="String" />
                 </SelectParameters>
                 <DeleteParameters>
                     <asp:Parameter Name="KeyID" Type="Int32" />
                 </DeleteParameters>
                 <UpdateParameters>
                     <asp:Parameter Name="FIFullKey_FIFacilityInfo" Type="String" />
                     <asp:Parameter Name="KeyCode" Type="String" />
                     <asp:Parameter Name="Accesses" Type="String" />
                     <asp:Parameter Name="KeyRingID" Type="Int32" />
                     <asp:Parameter Name="FileKey" Type="Boolean" />
                     <asp:Parameter Name="Active" Type="Boolean" />
                     <asp:Parameter Name="Restricted" Type="Boolean" />
                     <asp:Parameter Name="Emergency" Type="Boolean" />
                     <asp:Parameter Name="HookID" Type="Int32" />
                     <asp:Parameter Name="BrandID" Type="Int32" />
                     <asp:Parameter Name="ManufacturerKeyCode" Type="String" />
                     <asp:Parameter Name="KeyWayPinningCode" Type="String" />
                     <asp:Parameter Name="KeyCutCode" Type="String" />
                     <asp:Parameter Name="KeysComments" Type="String" />
                     <asp:Parameter Name="KeyID" Type="Int32" />
                 </UpdateParameters>
                 <InsertParameters>
                     <asp:Parameter Name="FIFullKey_FIFacilityInfo" Type="String" />
                     <asp:Parameter Name="KeyCode" Type="String" />
                     <asp:Parameter Name="Accesses" Type="String" />
                     <asp:Parameter Name="KeyRingID" Type="Int32" />
                     <asp:Parameter Name="FileKey" Type="Boolean" />
                     <asp:Parameter Name="Active" Type="Boolean" />
                     <asp:Parameter Name="Restricted" Type="Boolean" />
                     <asp:Parameter Name="Emergency" Type="Boolean" />
                     <asp:Parameter Name="HookID" Type="Int32" />
                     <asp:Parameter Name="BrandID" Type="Int32" />
                     <asp:Parameter Name="ManufacturerKeyCode" Type="String" />
                     <asp:Parameter Name="KeyWayPinningCode" Type="String" />
                     <asp:Parameter Name="KeyCutCode" Type="String" />
                     <asp:Parameter Name="KeysComments" Type="String" />
                 </InsertParameters>
             </asp:SqlDataSource>
             <asp:SqlDataSource ID="SqlDataSource8" runat="server" 
                 ConnectionString="<%$ ConnectionStrings:CDCWebConnectionString %>" 
                                
                 
                 SelectCommand="SELECT [FIFullKey], [FIFacilityName] FROM [FIFacilityInfo] WHERE ([FIFacilityCategory] = @FIFacilityCategory) ORDER BY [FIFacilityName]">
                 <SelectParameters>
                     <asp:Parameter DefaultValue="X" Name="FIFacilityCategory" Type="String" />
                 </SelectParameters>
             </asp:SqlDataSource>
 
</div>
</fieldset>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros