Autopostback Not Working

Last post 07-05-2009 2:27 AM by cbenaveen_1982. 8 replies.

Sort Posts:

  • Autopostback Not Working

    07-03-2009, 10:05 PM
    • Member
      point Member
    • bmarks
    • Member since 04-01-2009, 1:03 PM
    • Posts 13

    I have two dropdownlists that are databinding to a SQL database - the first is a list of casinos. When one of those is selected, what's supposed to happen is a list of comp codes for that casino is supposed to populate the second dropdownlist. However, nothing ever populates that dropdownlist. I have a database table for the casino names, another for the comp codes and names, and a third that matches up the casinos and comp codes ids. My query looks good, I think, but I figure out where the issue is. Here's the code I'm using. Any help would be great. Thanks!

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:Reservation %>"
                SelectCommand="SELECT [CasinoID], [CasinoName], [CasinoAbbr] FROM [Casino]">
            </asp:SqlDataSource>


            <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                ConnectionString="<%$ ConnectionStrings:Reservation %>"
                 SelectCommand="SELECT CasinoComp.CasinoID, CasinoComp.CompID, CompCode.CompID, CompCode.CompCode, CompCode.CompName FROM (CasinoComp INNER JOIN CompCode ON CompCode.CompID = CasinoComp.CompID) WHERE (CasinoComp.CasinoID = @CasinoID)">
                   
                <SelectParameters>
                    <asp:ControlParameter ControlID="CasinoID" Name="CasinoID"
                        PropertyName="SelectedValue"  />
                </SelectParameters>
            </asp:SqlDataSource>


            <asp:DropDownList ID="CasinoID" runat="server"
                DataSourceID="SqlDataSource1" DataTextField="CasinoName" AppendDataBoundItems="True" DataValueField="CasinoID" AutoPostBack="True">
                <asp:ListItem Selected="True" Value="-1">Choose Casino</asp:ListItem>
                  </asp:DropDownList>

            
            <asp:DropDownList ID="CompCode" runat="server"
                                        DataSourceID="SqlDataSource2" DataTextField="CompName"
                                        DataValueField="CasinoID">
            </asp:DropDownList>
        
        </div>
        </form>
    </body>
    </html>


  • Re: Autopostback Not Working

    07-03-2009, 10:58 PM
    Answer
    • Member
      437 point Member
    • jewelhere
    • Member since 01-18-2009, 6:55 AM
    • Dhaka, Bangladesh
    • Posts 110

    are you missing OnSelectedIndexChanged in dropdownlist?


  • Re: Autopostback Not Working

    07-04-2009, 12:31 AM

    Yes, you can do your requirement in OnSelectedIndexChanged event of the drop down.

    Let me know if you still not get done with your requirement even even if you write that event.

    Regards,
    Ram Reddy Mekha, +91-994-840-4315
    http://abhiramreddymekha.blogspot.com

    Please Mark as Answer if the post helps you.
  • Re: Autopostback Not Working

    07-04-2009, 12:41 AM
    • All-Star
      21,990 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,705

    Ram Reddy Mekha:
    Yes, you can do your requirement in OnSelectedIndexChanged event of the drop down.

    He was bind the dropdownlist through SqlDatasource so he already pass the control parameter. i this will not solve his problem

    Either he should check the query..  or try code once againg properly

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: Autopostback Not Working

    07-04-2009, 12:24 PM
    • Member
      point Member
    • bmarks
    • Member since 04-01-2009, 1:03 PM
    • Posts 13

    I've gone through my query countless times, but can't seem to find a problem with it. Do you see anything that might be wrong with the way it is written? Thanks.

  • Re: Autopostback Not Working

    07-04-2009, 1:04 PM

    it seems to be there is nothing wrong in your code. I executed your example in my system with some sample data. It executed properly and gave the expected results only.

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: Autopostback Not Working

    07-04-2009, 5:42 PM
    • Member
      point Member
    • bmarks
    • Member since 04-01-2009, 1:03 PM
    • Posts 13

    Wow. Well, it must be something I'm doing in my database then. In the CompCode table, I have CompID as the primary key with an integer datatype and then I have CompName and CompCode with varchar datatypes. In CasinoComp, I have CompID and CasinoID with both having integer datatypes. The Casino db pulls in the info fine in the first dropdownlist. Just nothing shows up in the second dropdown when I select a Casino, so I thought the problem was with the InnerJoin I set up between the two tables CompCode and CasinoComp. If you have it working with the same code and query, I really am lost to what I'm doing wrong.

  • Re: Autopostback Not Working

    07-05-2009, 2:08 AM
    Answer
    2 reasons. either data may not exists in db or although u r getting data, in front-end u r losing that data. take that query of your seconddatasource, and run that query in your sql server, with the sample casinoid and check whether data returning or not. if its returning, means query is ok. In your code-behind, some where else problem. if u have sql profiler, open that profiler, check what's the query executing, when u changed your casinos dropdownlist.
    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: Autopostback Not Working

    07-05-2009, 2:27 AM

     Make sure that the inner join parameters exist. i.e there is a match between the fields of the two different tables.

Page 1 of 1 (9 items)