Click here to Skip to main content
15,668,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.



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"]);
Share this answer
Ankit Rajput 22-Mar-11 8:39am    
One more thing i want to add here.

Now you need to handle SelectedIndexedChanged Event to pass the values to the database.
Why don't you create a separate struct, something like this:

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

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.
Share this answer
You can also populate the droplist using the query like
select cast(id as varchar) +' '+Range1+' '+Range2 as test from table1

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900