DataBound DropDownList Questions (2)
-
Hello All, This may be a simple enough questions but I cannot seem to make them work for me, therefore I am looking for any breadcrumbs that you guys can offer. I have a simple DropDownList that is bound to an SQL DataSource that just pulls users names from a table. No problem there. What I need to do in certain situations are the following: A - Add a new item to the list (No User) B - Have that new item first in the list as being selected. I have tried adding the .ADD method to the DataBound event, and it appears to be run but that value is not in the list after the page loads. Additionally I cannot make any other items in the list selected (instead of USERA being displayed I would like USERC displayed upon load). Any assistance will be appreciated.
-
Hello All, This may be a simple enough questions but I cannot seem to make them work for me, therefore I am looking for any breadcrumbs that you guys can offer. I have a simple DropDownList that is bound to an SQL DataSource that just pulls users names from a table. No problem there. What I need to do in certain situations are the following: A - Add a new item to the list (No User) B - Have that new item first in the list as being selected. I have tried adding the .ADD method to the DataBound event, and it appears to be run but that value is not in the list after the page loads. Additionally I cannot make any other items in the list selected (instead of USERA being displayed I would like USERC displayed upon load). Any assistance will be appreciated.
-
You can do one thing when you want ot add user at that time don't bind it from datasource just add user using .ADD else bind it to datasource. if you want ot make it more custom read each item from database one by one and add it.
Cheers!! Brij
-
I thought I would have to code it but I wasn't sure if it could be done without the coding. So that answers that, but how do I make a specific one selected?
-
There are two prperties of dropdownlist SelectedIndex and SelectedValue.If you know which item/index you need to show as selected then you can set it by above properties.
Cheers!! Brij
-
Hello All, This may be a simple enough questions but I cannot seem to make them work for me, therefore I am looking for any breadcrumbs that you guys can offer. I have a simple DropDownList that is bound to an SQL DataSource that just pulls users names from a table. No problem there. What I need to do in certain situations are the following: A - Add a new item to the list (No User) B - Have that new item first in the list as being selected. I have tried adding the .ADD method to the DataBound event, and it appears to be run but that value is not in the list after the page loads. Additionally I cannot make any other items in the list selected (instead of USERA being displayed I would like USERC displayed upon load). Any assistance will be appreciated.
After you pull data in DropDownList1 from tabel then add new item by code:
DropDownList1.Items.Add(new ListItem("Please select one user","")); DropDownList1.SelectedValue = "";
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.