从下拉列表中检索单个值,每个值都取自多列. [英] Retrieving single value from the dropdownlist which has each value taken from multiple columns.

查看:71
本文介绍了从下拉列表中检索单个值,每个值都取自多列.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我从数据库中填充了一个下拉列表,其中包含3列的值.
这是代码:

Hi,
I have populated a dropdownlist with values of 3 columns from the database.
This is the code:

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()));
        }



现在我的问题是,如何从下拉列表中的选定值(具有3列的值)中仅检索一列的值?

谢谢,
Prabhu.



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.

推荐答案

如何从下拉列表中的选定值(具有3列的值)中仅检索一列的值
您可以使用-"作为定界符,并将选定的值重新分成3个值.选择一个你想要的.
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.
string[] selectedValue = ddlProducts.SelectedValue.Split('-');
// Now use selectedValue[0] or selectedValue[1] or selectedValue[2]


这篇关于从下拉列表中检索单个值,每个值都取自多列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆