Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Need sqldatasource1_Selecting to fire within SelectedIndexChanged...

  • 06-10-2010 7:23pm
    #1
    Closed Accounts Posts: 585 ✭✭✭


    Hi Folks,

    I have an SQL datasource set up on my ASP.NET page, it works fine, but the idea is that I need it to refresh itself based on a dropdown list option being changed.

    When my page loads, my datasource goes off and pulls a list of data from my DB based on how the dropdownlist loads on PageLoad. Then it populates a Gridview with the data. This all works fine, as in everything loads and I don't have any errors.

    What I now need it to do is basically refresh the datasource and repopulate the Gridview if the user selects another option from the dropdownlist...

    So have two functions in my code, one for the SQL datasource...

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
    if (User.Identity.IsAuthenticated)
    {
    e.Command.Parameters["@MyProductID"].Value = Int32.Parse(DropDown1SelectedValue);
    }

    }



    I've set up the code in my sqldatasource on my aspx page to go off to my DB and collect the data where "the numeric values in a certain column = my value @MyProductID" and this is working as it should. And then I have the function for the SelectedIndexChanged...

    void DropDown1SelectedIndexChanged(object sender, EventArgs e)
    {
    }


    I'm not too clear though on how I should best go about getting by sqldatasource to reload and take in a new value based on the new dropdown1.SelectedValue??? :confused::confused::confused:

    Any suggestions as always hugely appreciated!


Comments

  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    Got it sorted very easily folks by sticking GridView1.DataBind(); into my SelectedIndexChanged function, it must refresh the sqldatasouce when that happens...


  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    You need to read up a bit more on using the SQLDataSource, specifically re its SelectParameter collection, and what kind of parameters it can contain. You don't need those event handlers.


  • Closed Accounts Posts: 585 ✭✭✭MrDarcy


    You need to read up a bit more on using the SQLDataSource, specifically re its SelectParameter collection, and what kind of parameters it can contain. You don't need those event handlers.

    Unfortunately I'm just developing this site myself to get it up and running, once it's taking in revenue, first thing I'll be doing is hiring someone much much more competent than myself to attend to all of this!


  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    MrDarcy wrote: »
    Unfortunately I'm just developing this site myself to get it up and running, once it's taking in revenue, first thing I'll be doing is hiring someone much much more competent than myself to attend to all of this!

    Fair enough, though I'd generally advise doing it the other way around. If this is a commercial project, at least have a read of this;
    http://msdn.microsoft.com/en-us/library/ms161953.aspx
    (this isn't as much an issue with SQLDataSource's, but if you're building queries by hand as you were in your other thread, it is once user input gets involved, intentionally or otherwise.)


Advertisement