在下拉列表中添加两个带范围号的范围. [英] adding two ranges with range number to Drop Down List.

查看:48
本文介绍了在下拉列表中添加两个带范围号的范围.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我从数据库中获取Range1和Range2.数据集如下所示.

范围1范围2
AB100 XY200
AB300 XY400
AB500 XY600

我必须将这些范围绑定到下拉列表中,作为列表项,包括我应用程序中的范围编号.
因此列表项应类似于==> 1 AB100 XY200.当用户选择一个范围时,我必须将Range1和Range2传递给数据库.
如何将具有范围号的两个范围绑定到下拉列表.

问候,
JN

Hi friends,

I am getting Range1 and Range2 from database. Dataset is like below.

Range1 Range2
AB100 XY200
AB300 XY400
AB500 XY600

I have to bind these ranges to a Drop Down List as list items includung range number in my application.
So list item should be like ==> 1 AB100 XY200 . When user selects a range I have to pass Range1 and Range2 to database.
How can I bind the two ranges with range number to Drop Down List.

Regards,
JN

推荐答案

hi


使用这样的查询

从测试
中选择Id,Range1 + Range2作为范围
然后将其绑定到下拉列表,例如
hi


use Query like this

select Id,Range1+Range2 as Range from test

and then bind it to the dropdown like
DropDownList1.DataSource = ds;
            DropDownList1.DataTextField = Convert.ToString(ds.Tables[0].Rows[0]["Range"]);
            DropDownList1.DataValueField = Convert.ToString(ds.Tables[0].Rows[0]["Id"]);
            DropDownList1.DataBind();


为什么不创建单独的结构,如下所示:

Why don''t you create a separate struct, something like this:

private struct RangeStruct
    {
        public string name;
        public string upperRange;
        public string lowerRange;
    }



然后您可以将数据集转换为RangeStruct的集合并绑定到该集合.然后,当用户从下拉列表中选择一个范围时,您便拥有了所需的所有信息.



then you can convert your dataset into a collection of RangeStruct and bind to that. Then when your user selects a range from your dropdownlist you have all the info you need.


您还可以使用查询
来填充下拉列表
You can also populate the droplist using the query like
select cast(id as varchar) +' '+Range1+' '+Range2 as test from table1



当您传递给db时,请分割ID并保存范围.



While you pass to db split the Id and save the ranges.


这篇关于在下拉列表中添加两个带范围号的范围.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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