?
Solved

Gridview Partially Updating

Posted on 2011-03-16
3
Medium Priority
?
372 Views
Last Modified: 2012-05-11
I have a gridview that is separated into a commandfield and 2 templatefields.  The 2nd templatefield updates properly when using the edit feature from the command field, but the first templatefield which has multiple pieces of data does not work and I cannot figure out why.  Here is the code - can anyone tell me what I'm doing wrong?
<!-- Gridview displaying Site information -->        
        <asp:Label ID="lblSiteHeader" runat="server" Text="Site Info" CssClass="header"></asp:Label>
        <asp:GridView ID="gvSite" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="unique_id" DataSourceID="SqlDataSource1" Width="1000px" 
            CellPadding="4" GridLines="Horizontal" ForeColor="#333333" 
            onselectedindexchanged="gvSite_SelectedIndexChanged">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/cancel1.gif" 
                    EditImageUrl="~/Images/edit.gif" ShowEditButton="True" 
                    UpdateImageUrl="~/Images/update.gif" >
                <ItemStyle Width="60px" />
                </asp:CommandField>
                <asp:TemplateField>
                    <HeaderTemplate>Site:</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Table ID="tblSite" BorderStyle="None" runat="server" GridLines="Horizontal" BorderWidth="0" CellPadding="2" Width="400">
                            <asp:TableRow CssClass="borderbottom">
                                <asp:TableCell CssClass="borderbottom" HorizontalAlign="Right" Width="150">Site:&nbsp;</asp:TableCell>
                                <asp:TableCell CssClass="borderbottom" HorizontalAlign="Left" Width="340"><asp:Label ID="lblSiteID" runat="server" Text='<%# Bind("site_id") %>'></asp:Label></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow ID="trSiteName" CssClass="borderbottom">
                                <asp:TableCell HorizontalAlign="Right">Name:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:Label ID="lblSiteName" CssClass="smallfont" runat="server" Text='<%# Bind("site_name") %>'></asp:Label></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow ID="trSiteVPNType" CssClass="borderbottom">
                                <asp:TableCell HorizontalAlign="Right">VPN Type:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:Label ID="lblSiteVPNType" runat="server" Text='<%# Bind("site_vpn_type") %>'></asp:Label></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow ID="trSiteVPNUser" CssClass="borderbottom">
                                <asp:TableCell HorizontalAlign="Right">VPN Login:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:Label ID="lblSiteVPNUser" runat="server" Text='<%# Bind("site_vpn_username") %>'></asp:Label></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow ID="trSiteVPNPass" CssClass="borderbottom">
                                <asp:TableCell HorizontalAlign="Right">VPN Password:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:Label ID="lblSiteVPNPass" runat="server" Text='<%# Bind("site_vpn_password") %>'></asp:Label></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow ID="trSiteHost" CssClass="borderbottom">
                                <asp:TableCell HorizontalAlign="Right">Host:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:Label ID="lblSiteHost" runat="server" Text='<%# Bind("site_host") %>'></asp:Label></asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </ItemTemplate>
                     <EditItemTemplate>
                        <asp:Table ID="tblSiteEdit" runat="server" GridLines="Horizontal">
                            <asp:TableRow>
                                <asp:TableCell HorizontalAlign="Right">Site:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:Label ID="lblSiteIDEdit" runat="server" Text='<%# Bind("site_id") %>'></asp:Label></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell HorizontalAlign="Right">Name:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="tbSiteNameEdit" runat="server" Text='<%# Bind("site_name") %>'></asp:TextBox></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell HorizontalAlign="Right">VPN Type:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="tbSiteVPNTypeEdit" runat="server" Text='<%# Bind("site_vpn_type") %>'></asp:TextBox></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell HorizontalAlign="Right">VPN Login:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="tbSiteVPNUserEdit" runat="server" Text='<%# Bind("site_vpn_username") %>'></asp:TextBox></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell HorizontalAlign="Right">VPN Password:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="tbSiteVPNPassEdit" runat="server" Text='<%# Bind("site_vpn_password") %>'></asp:TextBox></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell HorizontalAlign="Right">Host:&nbsp;</asp:TableCell>
                                <asp:TableCell HorizontalAlign="Left">
                                <asp:TextBox ID="tbSiteHost" runat="server" Text='<%# Bind("site_host") %>'></asp:TextBox>
                                </asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </EditItemTemplate>
                    <ItemStyle Width="500px" />
               </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Notes:</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblSiteNotes" runat="server" Text='<%# Bind("site_notes") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="tbSiteNotesEdit" runat="server" Text='<%# Bind("site_notes") %>' TextMode="MultiLine" Height="150" Width="440"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemStyle Width="450px" />
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        
        <!-- SqlDataSource1 - linked to gvSite -->        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnMgrCS %>" 
            SelectCommand="SELECT * FROM [hd_site] WHERE ([site_id] = @site_id)" 
            UpdateCommand="UPDATE [hd_site] SET [site_name] = @site_name, [site_vpn_type] = @site_vpn_type, [site_vpn_username] = @site_vpn_username, [site_vpn_password] = @site_vpn_password, [site_host] = @site_host, [site_notes] = @site_notes WHERE ([unique_id] = @unique_id)">
            <SelectParameters>
                <asp:QueryStringParameter Name="site_id" QueryStringField="site" 
                    Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="site_name" Type="String" />
                <asp:Parameter Name="site_vpn_type" Type="String" />
                <asp:Parameter Name="site_vpn_username" Type="String" />
                <asp:Parameter Name="site_vpn_password" Type="String" />
                <asp:Parameter Name="site_host" Type="String" />
                <asp:Parameter Name="site_notes" Type="String" />
                <asp:Parameter Name="unique_id" Type="Int32" />
                <asp:Parameter Name="site_id" Type="String" />
            </UpdateParameters>

Open in new window

0
Comment
Question by:rondre
[X]
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
  • 2
3 Comments
 

Author Comment

by:rondre
ID: 35150419
I found the problem - for some reason the values wouldn't bind being in an asp:table.  when i used classic table tags <table> <tr><td> etc. it works fine.

Can anyone explain why the asp:table doesn't work?
0
 
LVL 14

Accepted Solution

by:
CtrlAltDl earned 2000 total points
ID: 35734272
Basically it becomes a child object of the asp:Table and not a child of the gridview.  So it became an object within an object (nested) so it lost focus of the bound data.

Sorry that may not be the best explanation, but I hope it gives you the right idea.
0
 

Author Closing Comment

by:rondre
ID: 35739491
Thanks - I figured it was something like that - am not familiar with using asp:table much and saw no reason i would need it so switched back to standard html table and it had worked - i appreciate the insight.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

800 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