View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique.
View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used during a post-back. For example, you can store information in view state that will be accessed during the page load event the next time the page is sent to the server.
Step1: Declare a class with Serializable attribute
[Serializable]
public class field
{
public int class_Id { get; set; }
public string adm_no { get; set; }
}
Step2: Store data in Viewstate
List<field> data = new List<field>();
foreach (GridViewRow g1 in gvstudentDetails.Rows)
{
field f1 = new field();
f1.adm_no=Convert.ToString((g1.FindControl("lbladm_no") as Label).Text);
f1.Class_Id=Convert.ToInt32(ddlclass.SelectedValue);
}
data.Add(f1);
ViewState["_data"] = data;
Step3: Retrieve data from viewstate
if (ViewState["_data"] != null)
{
List<field> fieldList = (List<field>)ViewState["_data"];
}
Note: You are storing list object in Viewstate, it may create performance overhead of the page. Secondly in your code it is redirect to some other page, means you won't the Viewstate value in other page.