Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropdownList and Ajax

Status
Not open for further replies.

NerdTop72

Programmer
Mar 14, 2005
117
US
Having a problem...
I have a Bound DropDownList to a SQL table, when selectedindex is changed it is suppose to update the text boxes and labels in the update panel. It is working but the page is still refreshing? This latest code, I tried to move the Dropdownlist out of the Update Panel to see if that was the problem. It wasn't... I get the same results. an entire page refresh? I was watching this how to video ASP.NET AJAX: A demonstration of ASP.NET AJAX They make a To do list using gridview and dropdownlist, but a data table instead of a SQLConnection. Can anyone see why this isn't working?

Thanks,
Jason

Code:
 <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AddAjaxTest.aspx.vb" Inherits="Default2" %>

<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
    </asp:ScriptManager>
                           <asp:DropDownList ID="DDLVendorName" runat="server" 
                            AppendDataBoundItems="True" 
                            DataSourceID="SqlVendorList" DataTextField="NAME" 
                            DataValueField="VENDORID" 
                            
        OnSelectedIndexChanged="DDLVendorName_SelectedIndexChanged" AutoPostBack="True">
                        </asp:DropDownList>   
                        
      <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
        <ContentTemplate>
            <table style="width:656px">
                <tr>
                    <td style="height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 113px;">
                        Vendor Name</td>
                    <td style="height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 200px;">

                    </td> 

                    <td style="height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 88px;">
                        Account Code</td>
                    <td style="width: 25px; height: 20px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black;">
                        <asp:DropDownList ID="DDLAcountCode" runat="server">
                            <asp:ListItem></asp:ListItem>
                            <asp:ListItem>740</asp:ListItem>
                            <asp:ListItem>743</asp:ListItem>
                            <asp:ListItem>930</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td style="height: 21px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 113px;">
                        Phone #</td>
                    <td style="height: 21px; width: 200px;">
                        <asp:Label ID="lblPhoneNumber" runat="server"></asp:Label>
                    </td>
                    <td style="height: 21px; border-left-width: thin; border-left-color: gray; width: 88px;">
                        PO Number</td>
                    <td style="width: 25px; height: 21px">
                        <asp:Label ID="lblPONumber" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="height: 21px; border-top-width: thin; border-left-width: thin; border-left-color: black; border-bottom-width: thin; border-bottom-color: black; border-top-color: black; border-right-width: thin; border-right-color: black; width: 113px;">
                        Fax #</td>
                    <td style="height: 21px; width: 200px;">
                        <asp:Label ID="lblFaxNumber" runat="server"></asp:Label>
                    </td>
                    <td style="height: 21px; width: 88px;">
                        Order #</td>
                    <td style="width: 25px; height: 21px">
                        <asp:Label ID="lblOrderNumber" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="height: 21px; width: 113px;">
                        Account Number</td>
                    <td style="height: 21px; width: 200px;">
                        <asp:Label ID="lblAccountNumber" runat="server"></asp:Label>
                    </td>
                    <td style="height: 21px; width: 88px;">
                        Order Date</td>
                    <td style="width: 25px; height: 21px;">
                        <asp:TextBox ID="txtOrderDate" runat="server" Width="64px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td style="height: 24px; width: 113px;">
                        Confirmation #</td>
                    <td style="height: 24px; width: 200px;">
                        <asp:TextBox ID="txtConfirmationNumber" runat="server" Width="184px"></asp:TextBox>
                    </td>
                    <td style="height: 24px; width: 88px;">
                    </td>
                    <td style="width: 25px; height: 24px;">
                    </td>
                </tr>
            </table>
            <br />
        
            <br />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="DDLVendorName" 
                EventName="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel> 
       <asp:SqlDataSource ID="SqlVendorList" runat="server" 
                ConnectionString="Data Source=server;Initial Catalog=LabPO;Persist Security Info=True;User ID=sa;Password=xxxx" 
                SelectCommand="SELECT * FROM [VENDORS] ORDER BY [NAME]"></asp:SqlDataSource>
    <br />
    <br />
    <br />
    <br />
    <table style="width: 100%">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
</asp:Content>


Here is the code behind page

Code:
    Protected Sub DDLVendorName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLVendorName.SelectedIndexChanged
        Dim MyConnection As System.Data.SqlClient.SqlConnection
        Dim MyDataAdapter As SqlClient.SqlDataAdapter
        Dim MyDataTable As New DataTable
        'Dim MyDataRow As DataRow
        Try


            Dim strSQL As String = "SELECT * from vendors where vendorID =" & Me.DDLVendorName.SelectedValue
            ' Connect and fill the DataTable  
            MyConnection = New System.Data.SqlClient.SqlConnection("Data Source=server;Initial Catalog=LabPO;Persist Security Info=True;User ID=sa;Password=xxxx")
            MyConnection.Open()
            MyDataAdapter = New SqlClient.SqlDataAdapter(strSQL, MyConnection)
            MyDataAdapter.Fill(MyDataTable)

            Me.lblFaxNumber.Text = MyDataTable.Rows.Item(0).Item("FAX")
            Me.lblPhoneNumber.Text = MyDataTable.Rows.Item(0).Item("phone")
            Me.lblPONumber.Text = MyDataTable.Rows.Item(0).Item("PONumber")
            Me.lblAccountNumber.Text = MyDataTable.Rows.Item(0).Item("contact")
        Catch ex As Exception
            'lblError.Text = "Error in DDLVendorName: " & ex.Message

        End Try
    End Sub
 
I created a new website in Visual Web Developer 2008 and then was able to add Ajax enabled asp pages... I added my code the same as above. The code does work how I want it to now! yay

The IDE doesn't even allow me to add Ajax enabled pages from the add item selection in my solution explorer while using Web Dev 2008. I do recall creating this site in Visual Studio's 2005 and ended up using Web Developer 2008, after a computer crash. The website I have been working on is currently using Framework 2.0.

The Ajax tools I have been trying to use must be based on the 3.5 framework. I am on my way, just have to remake my site...

O well, I've learned so much from tek-tips, i can try to make it better, and fancy with Ajax! Cool


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top