SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two Droplists bound to gridview and DB

    I am trying to find a tutorial on cascading droplists that work like this:

    1) State droplist is bound to DB and pulls all evident states in DB
    2) City droplist dynamically fills based on the value of the State droplist and shows all cities in the DB
    3) Gridview will then dynamically filter the data based on the State and City value and show the end user the data.

    I have not been able to find a tutorial that deals with TWO droplists.

    Can someone please lead me in the right direction?

    THANKS!!

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi NAWA-mark, I did see that site but it lacks the gridview function with filtering based on the two values. I'm not sure if I'm able enough to adapt it.

    Any ideas on how to implement the gridview?

    Thanks!!

  4. #4
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dude9er View Post
    ... Any ideas on how to implement the gridview?

    Thanks!!
    bind the gridview to a deferred linq operator (select) and then run the filters at the postback

    I did something similar with a listview on a simple blog system that would allow you to filter based on category:
    Code Csharp:
    			using (var dbc = new siteDataContext())
    			{
    				var blogPosts = pageItems.blogPosts(dbc);
    				HttpCookie catSelect = new HttpCookie("category");
    				// if a category is selected filter the results
    				if (categoryDropDown.Text != "0")
    				{
    					catSelect["catName"] = categoryDropDown.Text;
    					blogPosts = from p in blogPosts
    								where p.categoryID == Convert.ToInt32(categoryDropDown.Text)
    								select p;
    				}
    				else
    				{
    					catSelect["catName"] = "0";
    				}
    				Response.Cookies.Add(catSelect);
    				// blogs is my listview
    				blogs.DataSource = blogPosts.ToList();
    				blogs.DataBind();
    			}
    blogPosts is populated from a compiled query in this example but if a category is selected from the dropdown blogPosts in that category is selected out of blogPosts and being deferred it won't occur until it's needed. There's a lot more to it but that should give you the basic idea.

    Using your plan you can filter at the state dropdown and the city dropdown or just wait for the selection on the city dropdown.

  5. #5
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sooooo. What'd you come up with?

  6. #6
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Nawa-Mark, your suggestion was a little beyond my capability. I think what you are suggesting is better because of the ajax element.

    I ended up creating a datasource. The 2nd droplist is bound to the first and the gridview to display that correct data is bound to the value of both droplists. I wrapped everything in an update panel to bypass the auto-post screen flash. It works fine, but I'm not in love with it.

    I would like to bind the droplists to a button, when clicked the gridview is updated, I haven't started this step yet, and not sure if I'll be able to get it to work, but I will try.

    Thanks for your help!! It did lead me in the right direction.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •