[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Gridview Partially Updating

Posted on 2011-03-16
3
Medium Priority
?
375 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

829 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