我有一个下拉菜单。我需要绑定(bind)数据表值的两个字段 这里
ddlitem.datasource= dtitem
ddlitem.datatextfield = dtitem.cloumn["name"].tostring()+"-"+dtitem.cloumn["tagname"].tostring()
我正在这样做,我在这里遇到异常。如何组合下拉列表中的两个列值
当我检索下拉列表中选定的值时
我应该只获取此列值的值:dtitem.cloumn["name"].tostring()
string stritem= ddlitem.selecteditem.Text.Tostrigng();
那么我该如何分割字符串的值呢?
最佳答案
您需要迭代其中 1 列行,并且需要取消您的项目而不是整个列
编辑:
应该像...
for (int count = 0; count < dtitem.Rows.Count; count++)
{
dtitem.Rows[count]["name"] = dtitem.Rows[count]["name"].tostring() + "-" + dtitem.Rows[count]["tagname"].tostring();
}
关于c# - 如何在下拉列表中添加表字段的2列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1672206/