且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

关于从两列到单个下拉列表的数据的问题

更新时间:2023-02-11 19:43:39

我建​​议你在两列之间使用某种分隔符



例如更改您查询以下

选择Material_name +'!'+尺寸作为材料的全名



唯一需要注意的是分隔符在任何列中都不存在。由于我不知道你的数据,我提供了一个!作为分隔符。

您将更好地判断分隔符。



当您从下拉控件中收到值时,您可能会分裂分隔符处的数据值,并在insert语句中使用这些分隔值,并将其插入两个不同的列。
I would suggest that you use some kind of a separator between the two columns

for example change you query to the following
select Material_name+'!'+Size as fullname from Materials

The only thing you need to be careful about is that the separator does not exists in any of the columns. As I don't know your data I have provided a "!" as the separator.
You will be the better judge of the separator.

When you receive the value from the dropdown control you may split the data value at the separator and use these separated values in your insert statement and insert it in the two different columns.


试试这个



在你的查询中应该是两个列名之间的一个空格



选择Material_name +''+尺寸作为材料的全名







try this

in your query should be one space between two column name

select Material_name+' '+Size as fullname from Materials



String [] str=drpdownList.SelectedItem.ToString().Split('-');
String str1=str[0].Trim();
String str2=str[1].Trim();





str1获取第一列数据和str2获取第二列数据



了解更多关于拆分功能的信息

http://www.webblogsforyou .com / how-to-split-string-date-into-day-month-year / [ ^ ]


嗨Dude,



改变这样的代码



1)存储过程:



Hi Dude,

Alter your code like this

1)Stored Procedure :

SELECT
   (ISNULL(Material_name,'')+''+ISNULL(Size,'')) [MaterialNameText],
   (ISNULL(Material_name,'')+'#separator#'+ISNULL(Size,'')) [MaterialNameValue]
   FROM Materials





注意:在SQL concordinate中尝试使用isnull



2)在C#中代码





NOTE: In SQL concordinate try to use isnull

2)In C# Code

drpMaterialName.DataSource = ClassLibrary1.mainclass.dset("Purchase_Material_Name",    "");
        drpMaterialName.DataValueField = "MaterialNameValue";
        drpMaterialName.DataTextField = "MaterialNameText";
        DataBind()





在数据值字段中绑定MaterialNameValue(它包含分隔符)

绑定文本字段中的MaterialNameText







Bind MaterialNameValue in Data value Field (it contain separator)
Bind MaterialNameText in Text Field


String [] strValue=Convert.ToString(drpdownList.SelectedValue).Split('#separator#');
String Material_name=strValue[0].Trim();
String Size=strValue[1].Trim();





现在你可以很容易地将值存入db



注意:尝试使用Convert.ToString( )放入TOString()



Now you can easily store value into db

Note:Try to use Convert.ToString() insted of TOString()