473,473 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I add multiple items inside a dropdownlist using objectdatasource

375 Contributor
Hi,

I have used a object datasource and have populated the a field named Titles in dropdownlist.

Now I want Titles as well as AuthorName to be shown in the dropdown list. as

Hound of baskervilles/Sherlock holmes.



How do i do that in objectdatasource. Pls help

Regards

cmrhema
Jun 2 '09 #1
5 3557
r035198x
13,262 MVP
Wouldn't it be possible to bind the Dropdown to a List<string> instead and then add the strings in the collection in the format that you want?
Jun 2 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Your ObjectDataSource will have a property that the DropDownList will be bound to.

All you have to do is edit this property and make sure that it returns what you want to display.
Jun 3 '09 #3
cmrhema
375 Contributor
@r035198x
Yes I did the same and it worked.
Thnx
Jun 4 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
Hmmm somehow I answered your question (thinking it was you) when I was explaining things to someone else with a similar problem.

If you're still curious about using an ObjectDataSource instead of a List Of Strings check out this post :)
Jun 4 '09 #5
cmrhema
375 Contributor
@Frinavale
Yes, Actually I wanted a initially to display only titles, so I first went for ObjectDataSource(ODS), but then I wanted concatenation of title/author, so went for generic list, which I was partially aware of and did this way

And I concatenated as
Expand|Select|Wrap|Line Numbers
  1. ddlKeys.DataTextField = "KeyValue ";
Infact I call a method where I populate the generic list as below
Expand|Select|Wrap|Line Numbers
  1.   private void TGenerateKeys<T>(SqlDataReader returnData, ref List<Keys> KeysList)
  2.         {
  3.             while (returnData.Read())
  4.             {
  5.                 Keys oKeys = new Keys();
  6.                 oKeys.KeyValue = Convert.ToString(returnData["TITLE"]) + "/" + Convert.ToString(returnData["AUTHOR"]);
  7.  
  8.                 KeysList.Add(oKeys);
  9.             }
  10.         }
But although I have not implemented, I think, while retrieving query from sql server, I can put something as
select title+author as "Both" from tablename
and directly bind this value to ODS.

Of course I can bind the "KeyValue", field too, but I had one more work, I had to include a value called as "All", so if the user chooses "All", I should be able to display all the results.
If I add it through properties (I mean press F4 on dropdownlist), then although I select other titles, the dropdownlist always showed "All".(because I gave selected =true in dropdownlist)

I thought it would be easier if I dynamically populate the dropdownlist and after binding to the above list. I followed this code

Expand|Select|Wrap|Line Numbers
  1.  List<Keys> olistkeys=Keys.GetKeysByEmailId(txtEmail.Text);
  2.              ddlKeys.DataSource = olistkeys;
  3.              ddlKeys.DataTextField = "keyvalue";
  4.              ddlKeys.DataBind();
and later added the "All" as
Expand|Select|Wrap|Line Numbers
  1. ddlKeys.Items.Add(new ListItem("All", "0"));
And resolved my issues.

Sorry for dragging this to such a length, and pls excuse my English.

Regards
cmrhema
Jun 5 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Aaron Prohaska | last post by:
I'm having the problem with this drop down list on postback. For some reason both the ListItems get selected when I change the selected item. Using the code below I'm building the drop down list in...
2
by: .Net Newbie | last post by:
Hello, I am currently coding my ASP.Net pages in c# and have run into a question concerning Emails. I have four objects on a page (six including 2 buttons). The first is a subject line...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
4
by: J055 | last post by:
Hi I thought I was trying to do something very simple but I'm have a lot of trouble trying to do the following. <asp:FormView ID="fvGroups" runat="server" DataKeyNames="GroupID"...
6
by: AG | last post by:
I have a dropdownlist bound to an objectdatasource. I need to loop through all the items in the datasource to get the values of a column that is not used as the datatextfield or the datavaluefield....
0
by: 47computers | last post by:
Hello. I'm having a bit of difficulty with some DropDownList controls within templates in a DetailsView on my web form. Basically, I have a form where a user is building a "location profile" with...
1
by: bogdan | last post by:
Hi, I'd like to use a dropdownlist in a formview to map numeric values to 'user-friendly' descriptions. The dropdownlist items' values need to be bound to a column in a db table. For example,...
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.