本文介绍了需要组合2个字段才能在下拉列表中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 使用(SqlCommand sqlCmd = new SqlCommand()) { sqlCmd.CommandText =SELECT LNAME FROM PAYMAST; sqlCmd.Connection = sqlConn; sqlConn.Open(); SqlDataAdapter da = new SqlDataAdapter(sqlCmd); DataTable dt = new DataTable(); da.Fill(dt); DropDownList1.DataSource = dt; DropDownList1.DataValueField =LNAME; DropDownList1.DataTextField =LNAME; DropDownList1.DataBind(); sqlConn.Close(); 需要用2个字段的组合替换字段名称LNAME即 'FNAME'+''+'LNAME'。 你如何在上面的设置? 谢谢 我尝试了什么: 审核了我自己的代码和其他人以及网络,但没有发现这个场景解决方案 尝试: sqlCmd.CommandText = SELECT LNAME +''+ FNAME AS [Name] FROM PAYMAST; ... DropDownList1.DataValueField = 名称; DropDownList1.DataTextField = 名称; using (SqlCommand sqlCmd = new SqlCommand()) { sqlCmd.CommandText = "SELECT LNAME FROM PAYMAST"; sqlCmd.Connection = sqlConn; sqlConn.Open(); SqlDataAdapter da = new SqlDataAdapter(sqlCmd); DataTable dt = new DataTable(); da.Fill(dt); DropDownList1.DataSource = dt; DropDownList1.DataValueField = "LNAME"; DropDownList1.DataTextField = "LNAME"; DropDownList1.DataBind(); sqlConn.Close();Need to replace the field name 'LNAME' with a combination of 2 fields ie'FNAME' +' '+'LNAME'.How do you accomplish it in the settings above?ThanksWhat I have tried:Reviewed my own codes and others and the net , but found none close to this scenario 解决方案 Try:sqlCmd.CommandText = "SELECT LNAME + ' ' + FNAME AS [Name] FROM PAYMAST";...DropDownList1.DataValueField = "Name";DropDownList1.DataTextField = "Name"; 这篇关于需要组合2个字段才能在下拉列表中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 23:18