Click here to Skip to main content
16,015,755 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have populated a dropdownlist with values of 3 columns from the database.
This is the code:
C#
ddlProducts.DataSource = dsProductDetails.Tables[0];
        for (int i = 0; i < dsProductDetails.Tables[0].Rows.Count; i++)
        {
            ddlProducts.Items.Add(new ListItem(dsProductDetails.Tables[0].Rows[i]["ProductCode"].ToString() + "-" + dsProductDetails.Tables[0].Rows[i]["ProductName"].ToString() + "-" + dsProductDetails.Tables[0].Rows[i]["ProductBrand"].ToString()));
        }


Now my question is that, how do I retrieve value of only one column from the selected value(which has values from 3 columns) in the Dropdownlist?

Thanks,
Prabhu.
Posted
Updated 2-May-12 3:16am
v2

1 solution

how do I retrieve value of only one column from the selected value(which has values from 3 columns) in the Dropdownlist
You can use '-' as delimiter and split the selected value back into 3 values. Pick the one you want.
C#
string[] selectedValue = ddlProducts.SelectedValue.Split('-');
// Now use selectedValue[0] or selectedValue[1] or selectedValue[2]
 
Share this answer
 
Comments
VJ Reddy 2-May-12 10:18am    
Good answer. 5!
Sandeep Mewara 2-May-12 11:00am    
Thanks.
bpc1989 3-May-12 1:28am    
Thanks Sandeep..It worked!!
Sandeep Mewara 3-May-12 2:52am    
Good to know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900