如何在asp.net c#中为dropdownlist的datavaluefield分配多个值 [英] how to assign multiple values to datavaluefield of dropdownlist in asp.net c#

查看:108
本文介绍了如何在asp.net c#中为dropdownlist的datavaluefield分配多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况,



我正在使用Course_Master表,我想从中获取Course_name,Course_id和Stream。

我按以下方式将此记录绑定到下拉列表。



 DataSet ds = objExam.GetStudentPracticalSubject(Request.QueryString [  admission_id]。ToString()); 
ddSubject.DataSource = ds.Tables [ 0 ];
ddSubject.DataTextField = COURSE_NAME;
ddSubject.DataValueField = COURSE_ID;
ddSubject.DataBind();





上面的GetStudentPracticalSubject方法返回我的流也是,我想绑定也与dropdownlist,这样我就可以像使用属性ddSubject.SelectedValue一样传递stream。



我想知道如何使用多个DataValueField属性来实现这一点对于两个绑定值。

解决方案

解决方案:你可以做的是从SQl获取CourseID和Stream或任何数据库获取它们像'1-S'那里1是您的CourseID,S可以是您的streamID或流值。然后,您可以使用'split'函数来获取代码中的值。 :)

I am having following scenario,

I am having Course_Master table from which I want to get Course_name,Course_id and Stream.
I bind this record to dropdownlist in the following manner.

DataSet ds = objExam.GetStudentPracticalSubject(Request.QueryString["admission_id"].ToString());
                  ddSubject.DataSource = ds.Tables[0];
                  ddSubject.DataTextField = "COURSE_NAME";
                  ddSubject.DataValueField = "COURSE_ID";
                  ddSubject.DataBind();



the above GetStudentPracticalSubject method return me Stream also, I want to bind that also with the dropdownlist, so that It is possible for me to pass stream as like courseid using the propertity ddSubject.SelectedValue.

I want to know how to achieve this with multiple DataValueField property for two binding values.

解决方案

Solution: What you can do is when you get the CourseID and Stream from SQl or any database fetch them like '1-S' where '1' is your CourseID and 'S' can be your streamID or stream value. Then you can use the 'split' function to get the value in your code. :)


这篇关于如何在asp.net c#中为dropdownlist的datavaluefield分配多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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