Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends...
I want to bind the gridview records based on that Date field.
First i bind with today's date
when ever i clicking on the previous button my gridview data bind with previous day records.
when i click another time it will display day before previous day records pls help me...
Posted
Comments
Nilesh Patil Kolhapur 16-Apr-12 5:22am    
Give ur code what u try

Hi,

C#
private void BindGridView(DateTime HireDate)
{
    string ConString = ConfigurationManager.ConnectionStrings["ConString2"].ConnectionString;
    SqlConnection con = new SqlConnection(ConString);
    string CmdString = "Select EmployeeID, FirstName, LastName, Salary, HireDate FROM Employees ORDER BY Salary DESC";
    SqlCommand cmd = new SqlCommand(CmdString, con);
    DataSet ds = new DataSet();
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    sda.Fill(ds);
    DataView dv = ds.Tables[0].DefaultView;
    dv.RowFilter = "HireDate='"+HireDate+"'";
    GridView2.DataSource = dv;
    GridView2.DataBind();
}


You can call this function from different buttons as per your need
 
Share this answer
 
C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           lblDate.Text = DateTime.Now.Date.ToShortDateString();
           BindData();
       }
   }
   protected void BindData()
   {
       SqlCommand cmd = new SqlCommand("SELECT * from Records where Date='"+lblDate.Text+"'", con);
       SqlDataAdapter da = new SqlDataAdapter(cmd);
       DataSet ds = new DataSet();
       da.Fill(ds);
       GridView2.DataSource = ds;
       GridView2.DataBind();
   }
   protected void Previous_Click(object sender, EventArgs e)
   {
       DatePrevoius();

   }
   protected void DatePrevoius()
   {
       DateTime d1 = DateTime.Parse(lblDate.Text);
       var d2 = d1.AddDays(-1).ToShortDateString();
       lblDate.Text = d2.ToString();
       BindData();
   }
   protected void Button3_Click(object sender, EventArgs e)
   {
       NextDate();
   }
   protected void NextDate()
   {
       DateTime d1 = DateTime.Parse(lblDate.Text);
       var d2 = d1.AddDays(1).ToShortDateString();
       lblDate.Text = d2.ToString();
       BindData();
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900