asp.net state management issue help req'd
-
Hi, I have a gridview (source is a list) which contains information that would be required to pull out more data from the database. actually, i wil be using that list when a btn is clicked to retrieve more information and then assign this second list to the gridview... ie 1 grid and two sources but source 2 is dependent on source1. i am using asp.net so with button click , state is lost and i don't have anything in the list. How would i save this state... list1 has about 10 rows of 10 columns... i tried saving it in viewstate but page is showing error... plz provide help
haseeb
-
Hi, I have a gridview (source is a list) which contains information that would be required to pull out more data from the database. actually, i wil be using that list when a btn is clicked to retrieve more information and then assign this second list to the gridview... ie 1 grid and two sources but source 2 is dependent on source1. i am using asp.net so with button click , state is lost and i don't have anything in the list. How would i save this state... list1 has about 10 rows of 10 columns... i tried saving it in viewstate but page is showing error... plz provide help
haseeb
When you need the data in your gridview, write a method SaveGridView to datatable. Then you can work with that datatable and use it to create datasource2. I have a method like that in one of my applications, which I will post as an example. My example uses template fields in the grid, but you can work with datafields as well. Not once you call the saveGridToDataTable you can rebind the grid to the table you just created.
private DataTable saveGridToDataTable() { DataTable tbl = AppData.getEmptyOQTraineesTable(); int testScore = 0; foreach (GridViewRow row in this.gvResults.Rows) { if (row.Visible) { DataRow r = tbl.NewRow(); DateTime dValue = DateTime.Today; TextBox txtTestDate = (TextBox)row.FindControl("txtTestDate"); TextBox txtQaulificationDate = (TextBox)row.FindControl("txtQualificationDate"); TextBox txtScore = (TextBox)row.FindControl("txtScore"); TextBox txtEmpNumber = (TextBox)row.FindControl("txtEmpNumber"); if (string.IsNullOrEmpty(txtEmpNumber.Text)) r\["Employee"\] = DBNull.Value; else r\["Employee"\] = txtEmpNumber.Text; if (int.TryParse(txtScore.Text, out testScore)) r\["TestScore"\] = testScore; if (DateTime.TryParse(txtTestDate.Text, out dValue)) r\["TaskDate"\] = dValue; if (DateTime.TryParse(txtQaulificationDate.Text, out dValue)) r\["QualificationDate"\] = dValue; tbl.Rows.Add(r); } } return tbl; }
public static DataTable getEmptyOQTraineesTable()
{
string x = string.Empty;
DateTime y = DateTime.Today;
Int32 z = 0;DataColumn dc1 = new DataColumn(); dc1.DataType = x.GetType(); dc1.ColumnName = "Employee"; DataColumn dc3 = new DataColumn(); dc3.DataType = y.GetType(); dc3.ColumnName = "TaskDate"; DataColumn dc4 = new DataColumn(); dc4.DataType = z.GetType(); dc4.ColumnName = "TestScore"; DataColumn dc5 = new DataColumn(); dc5.DataType = y.GetType();
-
Hi, I have a gridview (source is a list) which contains information that would be required to pull out more data from the database. actually, i wil be using that list when a btn is clicked to retrieve more information and then assign this second list to the gridview... ie 1 grid and two sources but source 2 is dependent on source1. i am using asp.net so with button click , state is lost and i don't have anything in the list. How would i save this state... list1 has about 10 rows of 10 columns... i tried saving it in viewstate but page is showing error... plz provide help
haseeb
-
Hi, i don't get any compile time or runtime errors. i have to get values from table1 and then according to data of table 1, get table2 data using a button... i get data for table1 but when i click the btn, because http is stateless, i lose all the data that was in grid1... I need to maintain that data as state,so that in postback, i take out the data, do the searching and show table 2.... because table1 has alot of information, i don't know whether to save it in session,cookie or cache... also the data will change with each session, maybe 1 user will be checking one portion of table1 , other will be checking another portion... so how do i maintain all this detail... Thanx...
haseeb