Bindingdata into Table according to selection in t

2019-09-07 21:57发布

问题:

Using Visual Studio 2010 and SQL management Studio, I have created a page by which admin can get detail of student' result.

I have 7 drop downs in it.

  1. School
  2. Year
  3. Lesson
  4. Version
  5. Teacher
  6. Domain
  7. Learning Unit.

School and year is mandatory fields.

I have provided a button named Excel at the bottom of the page on clicking on which It dump the grid view made based on the selection into Excel.

right now I have done is on every dropdowns selected index change event I am binding the other dropdowns and also the gridview.

If the admin select any other dropdown in lower order it will reload the table according the changed selection.

So it takes a lot ot loading time for some selection.

Is It possible to make the code in button click event like on clicking on that it will first check which dropdowns are selected by admin and based on the only selected drop downs' value I can make the gridview and dump it into Excel.

回答1:

Inside the button click event write like,

        string s1 = "";
        string s2 = "";
        if (dropdown1.SelectedIndex > -1)
           s2 = dropdown1.Text.Trim();
        else
           s2 = "";
        if (dropdown2.SelectedIndex > -1)
            s1 = dropdown2.Text.Trim();
        else
            s1 = "";

based on this strings you can write query to get data from db and can bind this data to your gridview.