When page_load event is occured i am displaying entire data to the gridview. But initially both From Date and To Date's are empty and if i am trying to switch between pageindex of gridview then it shows above error.
Here is my page_load code...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Attributes.Add("readonly", "readonly");
TextBox2.Attributes.Add("readonly", "readonly");
myConn.Open();
SqlCommand cmd = new SqlCommand("select User_id, LoginDate from LoginLog", myConn);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
myConn.Close();
}
}
Here is my GridView1_PageIndexChanging code...
public void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string ToDate = "";
DateTime dtd = DateTime.Parse(TextBox2.Text);
dtd = dtd.AddDays(1);
ToDate = dtd.ToShortDateString();
myConn.Open();
SqlCommand cmd = new SqlCommand(@"select User_id , LoginDate from LoginLog where LoginDate between
('" + TextBox1.Text + "') and ('" + ToDate + "')", myConn);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
myConn.Close();
}