Monday, 22 July 2013

Convert Dataset to List Using Linq



public void test()
{
   DataSet ds = new DataSet();
   ds.Tables[0].Rows.Cast<System.Data.DataRow>().Select(p => new TestList()
   {
     Name = p["Resource_Number"].ToString(),
     City = p["ConnectionId"].ToString(),
     Class = p["ConnectionId"].ToString()
   }).ToList();
}

public class TestList
{
  public string Name { get; set; }
  public string City { get; set; }
  public string Class { get; set; }
}

Get Previous page Viewstate from this Page








Page1.aspx :
void btn_Click(object sender, EventArgs e)
{
  ViewState["Test"] = "Ajay";
  Server.Transfer("Page2.aspx");           
}
public string ReturnViewState()
{
  return ViewState["Test"].ToString();
}


Page2.aspx :

protected void Page_Load(object sender, EventArgs e)
{
  if (PreviousPage != null && PreviousPageViewState != null)
  {
    string str = PreviousPageViewState; //value will bw Ajay
  }
}
private string PreviousPageViewState
{
  get
  {
    string returnValue = null;
    if (PreviousPage != null)
    {
      Object objPreviousPage = (Object)PreviousPage;
      MethodInfo objMethod = objPreviousPage.GetType().GetMethod("ReturnViewState");
      //System.Reflection class
      return (String)objMethod.Invoke(objPreviousPage, null);
    }
    return returnValue;
  }
}