Solved

Gridview Partially Updating

Posted on 2011-03-16
3
358 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

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

19 Experts available now in Live!

Get 1:1 Help Now