Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Gridview Partially Updating

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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