Last post Feb 17, 2016 12:21 PM by ritmo2k
Feb 16, 2016 10:24 PM|Ritmo2k|LINK
I have a simple scenario where I want to populate a dropdown select. The data currently is the primary id for a row in a database table which works out to be what the user wants to see in the form.
The problem with this is that as they adjust the dropdown selection, they want a series of text boxes to reveal the related columns in the associated database row.
The dataset is small, one option is to hold the collection in memory instead of using events to constantly query the database, however that leads to a problem when in postback versus not.
What is the most efficient means to maintain this small collection of objects in memory to minimize the queries to refresh it? For each dropdown index changed event, I want to select the associated object from the collection and update the text boxes, then
optionally push this into Session for use in a redirect if they choose it by clicking an OK button?
Feb 17, 2016 01:16 AM|oned_gk|LINK
store datatabe in viewstate or session variable
Feb 17, 2016 09:27 AM|Yohann Lu|LINK
As oned_gk said, you can store datatabe in viewstate or session variable in memory. It will dynamically filter out the data from your table based on your dropdown selected value.
However, you can also use cache to store datatabe.
Firstly, when you load the page, you can stored the source data in Cache.
if (HttpContext.Current.Cache["SourceData"] == null)
HttpContext.Current.Cache["SourceData"] = dtTable;
Secondly, in dropdown selectedindexchange event, we could get cached datatable and filter datatable based on dropdown selected value, then we could populate textbox.
string value = DropDownList1.SelectedValue.ToString();
DataView dv = new DataView((DataTable)HttpContext.Current.Cache["SourceData"]);
dv.RowFilter = "No =" + value + " ";
foreach (DataRowView drv in dv)
Label1.Text = drv["Address"].ToString();
Feb 17, 2016 12:21 PM|Ritmo2k|LINK
Thanks for the added detail, using cache certainly affords some control I see.