Solved

Gridview Partially Updating

Posted on 2011-03-16
3
363 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
  • 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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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