troubleshooting Question

Gridview in Ajax Update Panel

Avatar of eharford
eharford asked on
ASP.NETAJAX
4 Comments1 Solution548 ViewsLast Modified:
Web page showing Gridview on rightThis page is using Multiviews.
I have gridview of Cattle Sales (on the right) that the farmer (on left) has bought at. As you can see there an "Add Sale" button outside of the gridview and the Update panel which adds a new sale to this list (through a dropdown box in View4). See asp.net code-
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="AddressList.aspx.vb" Inherits="Norton.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
        .style2
        {
            width: 588px;
            height: 53px;
        }
        .style3
        {
            height: 53px;
        }
        .style5
        {
            width: 741px;
            height: 53px;
        }
        .style6
        {
            width: 741px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<br />
     <asp:MultiView ID="MultiView1" runat="server">
    <asp:View ID="View1" runat="server">
    <br />
        Short Name:&nbsp; 
        <asp:DropDownList runat="server" Width="303px" 
            ID="DropDownList1"  Height="24px" AutoPostBack="True" 
            DataSourceID="SqlDataSource1" DataTextField="SNAME" DataValueField="LINKNO">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT DISTINCT [LINKNO], [SNAME], [NAME], [PREFIX] FROM [NDATA] ORDER BY [SNAME]">
        </asp:SqlDataSource>
        &nbsp;
        </asp:View>
    <asp:View ID="View2" runat="server">
    <br />
        Long Name:&nbsp; 
        <asp:DropDownList runat="server" Width="303px" 
            ID="DropDownList2"  Height="24px" AutoPostBack="True" 
            DataSourceID="SqlDataSource1" DataTextField="NAME" DataValueField="LINKNO">
        </asp:DropDownList>
        &nbsp;
        </asp:View>
    <asp:View ID="View3" runat="server">
    <br />
        Prefix:&nbsp; 
        <asp:DropDownList runat="server" Width="303px" 
            ID="DropDownList3"  Height="24px" AutoPostBack="True" 
            DataSourceID="SqlDataSource2" DataTextField="PREFIX" DataValueField="LINKNO">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT [LINKNO], [PREFIX] FROM [NDATA] WHERE ([PREFIX] IS NOT NULL) ORDER BY [PREFIX]">
        </asp:SqlDataSource>
        &nbsp;
        </asp:View>
        <asp:View ID="View4" runat="server">
            <table ID="Table1" runat="server" width="900px">
            <tr><td class="style6">
            <asp:Label ID="Label1" runat="server" Text="Search Name:" BackColor="#CCFFFF" 
                    Width="100px"></asp:Label>
                <asp:TextBox ID="txtSName" runat="server" 
                    Width="180px"></asp:TextBox>
            <asp:Label ID="Label13" runat="server" Width="79px" Text="LinkNo:" 
                    BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtLinkNo" runat="server" Width="58px" BackColor="#FF99FF" 
                    ReadOnly="True"></asp:TextBox>
                <asp:Label ID="Label14" runat="server" BackColor="#CCFFFF" Text="Incl:" 
                    Width="52px"></asp:Label><asp:CheckBox ID="CheckBox1" runat="server" />
            </td><td rowspan="12" class="style2">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="cmdAddS" />
                </Triggers>
                <ContentTemplate>
                        <asp:GridView ID="grSales" runat="server" AutoGenerateColumns="False" 
                        Caption="Sales" Height="250px" ShowHeader="False" Width="335px">
                        <Columns>
                            <asp:BoundField DataField="SaleNo" ReadOnly="True" />
                            <asp:BoundField DataField="SaleName" ReadOnly="True" />
                        </Columns>
                    </asp:GridView></ContentTemplate>
                    </asp:UpdatePanel>
            </td></tr>
            <tr><td class="style6"><asp:Label ID="Label2" runat="server" Text="Full Name:" BackColor="#CCFFFF" 
                    Width="100px"></asp:Label><asp:TextBox
                    ID="txtName" runat="server" Width="219px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label3" runat="server" Text="Address:" BackColor="#CCFFFF" 
                    Width="100px"></asp:Label><asp:TextBox ID="txtAdd1" runat="server" Width="221px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label4" runat="server" Width="100px"></asp:Label>
                <asp:TextBox ID="txtAdd2" runat="server" Width="224px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label5" runat="server" Width="100px"></asp:Label>
                <asp:TextBox ID="txtAdd3" runat="server" Width="224px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label6" runat="server" Width="100px" Text="County:" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtCounty" runat="server" Width="175px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label7" runat="server" Width="100px" Text="PostCode:" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtPCode" runat="server" Width="98px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style5"><asp:Label ID="Label9" runat="server" Width="100px" Text="Telephone:" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtTel" runat="server" Width="224px"></asp:TextBox></td>
                <td class="style3"></td></tr>
            <tr><td class="style6"><asp:Label ID="Label10" runat="server" Width="100px" Text="Status:" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtStatus" runat="server" Width="22px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label11" runat="server" Width="100px" Text="Herdsize:" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtHerdsize" runat="server" Width="22px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label8" runat="server" Width="100px" Text="Prefix:" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtPrefix" runat="server" Width="224px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label12" runat="server" Width="100px" Text="Breeder:" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtBreed" runat="server" Width="224px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6"><asp:Label ID="Label15" runat="server" Width="100px" 
                    Text="Notes (100 chs):" BackColor="#CCFFFF"></asp:Label>
                <asp:TextBox ID="txtNotes" runat="server" Width="449px"></asp:TextBox></td><td></td></tr>
            <tr><td class="style6">
                <asp:Button ID="cmdSave" runat="server" Text="Save" Width="78px" />&nbsp&nbsp&nbsp&nbsp<asp:Button ID="cmdDel"
                    runat="server" Text="Delete" Width="78px" />&nbsp&nbsp&nbsp&nbsp<asp:Button 
                    ID="cmdCancel" runat="server" Text="Cancel" Width="78px" />&nbsp&nbsp&nbsp&nbsp<asp:Button 
                    ID="cmdAdd" runat="server" Text=" Add Sale" Width="78px" />
                </td></tr>
            </table>
         </asp:View>
         <asp:View ID="View5" runat="server">
          <asp:DropDownList ID="DropDownList4" runat="server" 
            DataSourceID="SqlDataSource3" DataTextField="SALENO" DataValueField="SALENO" 
            Height="30px" Width="167px">
    </asp:DropDownList>&nbsp;&nbsp; <asp:Button ID="cmdAddS" runat="server" Text="Add Sale to Name" Width="130px" />
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT [SALENO] FROM [NSALNAME] ORDER BY [SALENO] DESC">
        </asp:SqlDataSource>
         </asp:View>
    </asp:MultiView>
</asp:Content>
The AddSale process works fine using simple SP ("AddSaleNo") but how would I get the panel to refresh without refreshing the farmer info? See attached vb code.
Protected Sub cmdAddS_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdAddS.Click
        Using NorConn = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
            NorConn.Open()
            Using uComm = New SqlCommand("AddSaleNo", NorConn)
                uComm.CommandType = Data.CommandType.StoredProcedure
                Dim param As New SqlParameter("@LINKNO", Data.SqlDbType.Float)
                param.Value = CInt(Me.txtLinkNo.Text)
                uComm.Parameters.Add(param)
                param = New SqlParameter("@SALENO", Data.SqlDbType.Float)
                param.Value = CInt(Me.DropDownList4.Text)
                uComm.Parameters.Add(param)
                Try
                    uComm.ExecuteNonQuery()
                Catch
                    Err.GetException.ToString()
                Finally
                End Try
            End Using
        End Using
        Me.MultiView1.ActiveViewIndex = 3
    End Sub
With thanks in advance
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros