Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. rebind Gridview after filtering with dropdownlist

rebind Gridview after filtering with dropdownlist

Scheduled Pinned Locked Moved ASP.NET
question
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Albert83
    wrote on last edited by
    #1

    Hi, I have a gridview which is bound to a acessdatasource at page load. I also have a dropdownlist bound to a datasource with a list of countries. How do I rebind the gridview after a certain country was selected from the dropdown list? Thank you.

    G C 2 Replies Last reply
    0
    • A Albert83

      Hi, I have a gridview which is bound to a acessdatasource at page load. I also have a dropdownlist bound to a datasource with a list of countries. How do I rebind the gridview after a certain country was selected from the dropdown list? Thank you.

      G Offline
      G Offline
      gauthee
      wrote on last edited by
      #2

      You have to write your coding in item_command event of the datagrid. when you add the dropdown to your datagrid specify the commandname as'xxxx' then in your itemcommand event you give : if(e.commandname=="xxxx") the selcted value from the ddl can be sent ot database and you can retrieve information accrdingly and finally bind the datagrid again.

      Gautham

      A 1 Reply Last reply
      0
      • G gauthee

        You have to write your coding in item_command event of the datagrid. when you add the dropdown to your datagrid specify the commandname as'xxxx' then in your itemcommand event you give : if(e.commandname=="xxxx") the selcted value from the ddl can be sent ot database and you can retrieve information accrdingly and finally bind the datagrid again.

        Gautham

        A Offline
        A Offline
        Albert83
        wrote on last edited by
        #3

        I am using Asp.net 2.0 there is no datagrid anymore. Thanks for your reply

        1 Reply Last reply
        0
        • A Albert83

          Hi, I have a gridview which is bound to a acessdatasource at page load. I also have a dropdownlist bound to a datasource with a list of countries. How do I rebind the gridview after a certain country was selected from the dropdown list? Thank you.

          C Offline
          C Offline
          Chetan Ranpariya
          wrote on last edited by
          #4

          Hi, Have you put the dropdown list in the gridview or outside the gridview? If its outside then you can create an event handler to handle SelectedIndexChanged event of DropDownList and filter data there and bind the gridview again.

          Thanks and Regards, Chetan Ranpariya

          A 1 Reply Last reply
          0
          • C Chetan Ranpariya

            Hi, Have you put the dropdown list in the gridview or outside the gridview? If its outside then you can create an event handler to handle SelectedIndexChanged event of DropDownList and filter data there and bind the gridview again.

            Thanks and Regards, Chetan Ranpariya

            A Offline
            A Offline
            Albert83
            wrote on last edited by
            #5

            The dropdown is outside of the gridview. This is asp.net 2.0 not 1.1. So I initially bind the gridview do accessdatasource. And then inside gridview there is a datasourceid property. So I knew how to rebind in asp.net 1.1 I don't know how to rebind in asp.net 2.0. Thank you

            C 1 Reply Last reply
            0
            • A Albert83

              The dropdown is outside of the gridview. This is asp.net 2.0 not 1.1. So I initially bind the gridview do accessdatasource. And then inside gridview there is a datasourceid property. So I knew how to rebind in asp.net 1.1 I don't know how to rebind in asp.net 2.0. Thank you

              C Offline
              C Offline
              Chetan Ranpariya
              wrote on last edited by
              #6

              Hi, You can create your AccessDataSource with parameters and on the click event of button you can provide value that parameter. The following is the example of parameterized AccessDataSource Here AccessDataSource1 has one parameter "CategoryID" which will need a integer value. Also you can see the WHERE clause in the SelectCommand Property of the AccessDataSouce1. The following code shows you how a value is assigned to the paramter of AccessDataSource1 and GridView is rebounded. protected void Button1_Click(object sender, EventArgs e) { AccessDataSource1.SelectParameters[0].DefaultValue = ddlCategories.SelectedValue; GV.DataBind(); } Here ddlCategories is the dropdownlist whose value I am passing to the parameter of the AccessDataSource1. I hope this will help you. -- modified at 2:01 Tuesday 24th April, 2007 Thanks and Regards, Chetan Ranpariya

              A 1 Reply Last reply
              0
              • C Chetan Ranpariya

                Hi, You can create your AccessDataSource with parameters and on the click event of button you can provide value that parameter. The following is the example of parameterized AccessDataSource Here AccessDataSource1 has one parameter "CategoryID" which will need a integer value. Also you can see the WHERE clause in the SelectCommand Property of the AccessDataSouce1. The following code shows you how a value is assigned to the paramter of AccessDataSource1 and GridView is rebounded. protected void Button1_Click(object sender, EventArgs e) { AccessDataSource1.SelectParameters[0].DefaultValue = ddlCategories.SelectedValue; GV.DataBind(); } Here ddlCategories is the dropdownlist whose value I am passing to the parameter of the AccessDataSource1. I hope this will help you. -- modified at 2:01 Tuesday 24th April, 2007 Thanks and Regards, Chetan Ranpariya

                A Offline
                A Offline
                Albert83
                wrote on last edited by
                #7

                Hi, thank you for such a detailed reply. One issue is that you included the code in a button event handler. I have no button. Rather once an item was selected from an dropdown category the viewgrid should be rebound. Maybe I didn't clearly understand your explanation. Thank you.

                C 1 Reply Last reply
                0
                • A Albert83

                  Hi, thank you for such a detailed reply. One issue is that you included the code in a button event handler. I have no button. Rather once an item was selected from an dropdown category the viewgrid should be rebound. Maybe I didn't clearly understand your explanation. Thank you.

                  C Offline
                  C Offline
                  Chetan Ranpariya
                  wrote on last edited by
                  #8

                  Hi, If you want your grid to be rebound when an item is selected in the dropdownlist, then you should write the code in the "SelectedIndexChanged" event of the DropDownList. protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e) { AccessDataSource1.SelectParameters[0].DefaultValue = ddlCategories.SelectedValue; GV.DataBind(); } I hope this will help you.

                  Thanks and Regards, Chetan Ranpariya

                  A 1 Reply Last reply
                  0
                  • C Chetan Ranpariya

                    Hi, If you want your grid to be rebound when an item is selected in the dropdownlist, then you should write the code in the "SelectedIndexChanged" event of the DropDownList. protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e) { AccessDataSource1.SelectParameters[0].DefaultValue = ddlCategories.SelectedValue; GV.DataBind(); } I hope this will help you.

                    Thanks and Regards, Chetan Ranpariya

                    A Offline
                    A Offline
                    Albert83
                    wrote on last edited by
                    #9

                    Thank you. I will try it. But I understand the solution. It seems that it got even simpler in asp.net 2.0. I assumed you have to create a datasource and then assign it to the gridview. And from what I see you just wrote gv.databind() Thanks alot for your assistance.

                    C 1 Reply Last reply
                    0
                    • A Albert83

                      Thank you. I will try it. But I understand the solution. It seems that it got even simpler in asp.net 2.0. I assumed you have to create a datasource and then assign it to the gridview. And from what I see you just wrote gv.databind() Thanks alot for your assistance.

                      C Offline
                      C Offline
                      Chetan Ranpariya
                      wrote on last edited by
                      #10

                      Hi, No need to say thanks. One thing I would like to remind you that dont forget to set "AutoPostBack" property of DropdownList to "true".

                      Thanks and Regards, Chetan Ranpariya

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups