RhythmAddict112
Programmer
Hi All,
Im tryin to cache a drop down list....if it isn't postback, i'm queryin the DB to populate the dropdown, and utilzing a dataset. -- I'm not married to using a dataset if there is a more efficient way of doing so. So suggestions are welcome, my main problem though...is restoring the DataTextField & DataValueField's of the DDL when I restore from cache...
All hail the INTERWEB!
Im tryin to cache a drop down list....if it isn't postback, i'm queryin the DB to populate the dropdown, and utilzing a dataset. -- I'm not married to using a dataset if there is a more efficient way of doing so. So suggestions are welcome, my main problem though...is restoring the DataTextField & DataValueField's of the DDL when I restore from cache...
Code:
void buildStatusDDL()
{
DropDownList1.ID = "DropDownList1";
DropDownList1.Visible = true;
DropDownList1.AutoPostBack = true;
DropDownList1.EnableViewState = true;
ListItem ListItem0 = new ListItem();
ListItem0.Text = "None";
ListItem0.Value = "0";
DropDownList1.Items.Add(ListItem0);
System.Data.DataSet dsDdl = new System.Data.DataSet();
if(Cache["Status"]==null)
{
string mySelectQuery="select statusgroupcd, description from prtadmin.statusgroup";
OleDbConnection myConnection = new OleDbConnection(Db2Conn);
myConnection.Open();
OleDbDataAdapter cmd = new OleDbDataAdapter(mySelectQuery,myConnection);
cmd.Fill(dsDdl,"Table");
DropDownList1.DataSource = dsDdl.Tables[0];
DropDownList1.DataTextField = dsDdl.Tables[0].Columns["description"].ColumnName.ToString();
DropDownList1.DataValueField = dsDdl.Tables[0].Columns["statusgroupcd"].ColumnName.ToString();
DropDownList1.DataBind();
Cache["Status"] = (DataSet)dsDdl;
cmd.Dispose();
myConnection.Close();
}
else
{
[COLOR=#ff0000]
//How do I assign these? If I provide the following code just populates my dropdown with
//"System.Data.DataRowView" -- I assume I have to specify the value and text fields, but don't know how....[/color]
DropDownList1.DataSource = (DataSet)Cache["Status"];
DropDownList1.DataBind();
}
//Page.Controls.Add(DropDownList1);
PlaceHolder1.Controls.Add(DropDownList1);
}
All hail the INTERWEB!