Avatar of Edward Harford
Edward Harford
 asked on

Gridview in Ajax Update Panel

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>

Open in new window

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

Open in new window

With thanks in advance
AJAXASP.NET

Avatar of undefined
Last Comment
disrupt

8/22/2022 - Mon
disrupt

Edward Harford

ASKER
Thanks for your suggestion. I regret I am not good at Javascript. I have tried UpdatePanel. Do I need to rebind the datasource to the grid or should the Update Trigger do this for me?
Edward Harford

ASKER
Further to my earlier - It does and now works fine!  I didnt seem to need UpdatePanel.update.
Thanks all the same.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
disrupt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question