rebind Gridview after filtering with dropdownlist
-
-
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.
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
-
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
-
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.
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
-
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
-
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
-
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
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.
-
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.
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
-
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
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.
-
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.
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