Populate table fields on query execution

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2011-11-24T15:55:06Z Indexed on 2011/11/24 17:52 UTC
Read the original article Hit count: 203

Filed under:
|

I'm trying to build an ASP site that populates a Table based on the results of a selection in a ListBox. In order to do this, I've created a GridView table inside a div element. Currently the default behavior is to show all the items in the specified table in sortable order.

However, I'd like to refine this further to allow for display of matches based on the results from the ListBox selection, but am not sure how to execute this. The ListBox fires off a OnSelectionChanged event to the method defined below and the GridView element is defined as

<asp:GridView ID="dataListings"  runat="server" AllowSorting="True" 
                    AutoGenerateColumns="False" DataSourceID="LinqDataSource1" 
                    OnDataBinding="ListBox1_SelectedIndexChanged">

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int itemSelected = selectTopics.SelectedIndex;
        string[] listing = null;

        switch (itemSelected)//assign listing the array of course numbers
        {
            case 0: 
                break;
            case 1: 
                listing = arts;
                break;

            case 2:
                listing = currentEvents;
                break;

           .... More cases here

            default:
                listing = arts;
                break;


        }
        using (OLLIDBDataContext odb = new OLLIDBDataContext())
        {

            var q = 
                from c in odb.tbl_CoursesAndWorkshops 
                where listing.Contains(c.tbl_Course_Description.tbl_CoursesAndWorkshops.course_workshop_number) 
                select c;

            dataListings.DataSource = q;
            dataListings.DataBind();

        }
    }

However, this method never gets fired. I can see a request being made when changing the selection, but setting a breakpoint at the method declaration does nothing at all.

Based on this, setup, I have three related questions

  1. What do I need to modify to get the OnSelectionChanged event handler to fire?
  2. How can I alter the GridView area to be empty on page load?
  3. How do I send the results from the dataListings.DataBind() execution to show in the GridView?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about gridview