Shared DataSource

T

Tumurbaatar S.

My page contains 2..3 DropDownList's with identical content.
For example, country names. Is there a way to bound these lists
to one data source? I think DataReader cannot act as shared source
due to its forward-only nature. But can I do as shown below?

SqlDataAdapter cmd = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
cmd.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
list1.DataSource = dv;
list1.DataBind();
list2.DataSource = dv;
list2.DataBind();
.....
Or is there any other shorter/simpler method?
 
T

Tumurbaatar S.

Thank you!
If EnableStateView is true for all these DropDownLists,
ViewState will contain all items of all these lists. I.e. ViewState size
will be increased by (number of items in one list) * (number of list
controls).
Yes?


S. Justin Gengo said:
Tumurbaatar,

That looks like a fine way to do it.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Tumurbaatar S. said:
My page contains 2..3 DropDownList's with identical content.
For example, country names. Is there a way to bound these lists
to one data source? I think DataReader cannot act as shared source
due to its forward-only nature. But can I do as shown below?

SqlDataAdapter cmd = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
cmd.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
list1.DataSource = dv;
list1.DataBind();
list2.DataSource = dv;
list2.DataBind();
....
Or is there any other shorter/simpler method?
 
S

S. Justin Gengo

Yes, if viewstate is enabled then your page's viewstate field will contain
data for each drop down list.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Tumurbaatar S. said:
Thank you!
If EnableStateView is true for all these DropDownLists,
ViewState will contain all items of all these lists. I.e. ViewState size
will be increased by (number of items in one list) * (number of list
controls).
Yes?


S. Justin Gengo said:
Tumurbaatar,

That looks like a fine way to do it.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Tumurbaatar S. said:
My page contains 2..3 DropDownList's with identical content.
For example, country names. Is there a way to bound these lists
to one data source? I think DataReader cannot act as shared source
due to its forward-only nature. But can I do as shown below?

SqlDataAdapter cmd = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
cmd.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
list1.DataSource = dv;
list1.DataBind();
list2.DataSource = dv;
list2.DataBind();
....
Or is there any other shorter/simpler method?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top