Shared DataSource

  • Thread starter Thread starter Tumurbaatar S.
  • Start date Start date
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?
 
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?
 
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?
 
Back
Top