hello guyz , i need yor help , i cannot display the data between gridview when i filtering it in date , attach here is my source code in this project
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
-
-
- namespace onlinestudinformation
- {
- public partial class studentaccountlst : System.Web.UI.Page
- {
- SqlCommand cmd;
- SqlConnection cn;
- SqlDataAdapter da;
- SqlDataReader dr;
- public void connectdb()
- {
- cn = new SqlConnection(@"Data Source=LAPTOP-93441BLD\HUSSIEN;Initial Catalog=studentinfodb;Integrated Security=True");
- cn.Open();
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- this.connectdb();
- this.showlist();
- }
-
- }
- private void showlist()
- {
- this.connectdb();
- cmd = new SqlCommand("select *from tblOnlineuserregistration ", cn);
- dr = cmd.ExecuteReader();
- GridView1.DataSource = dr;
- GridView1.DataBind();
- }
-
- protected void btnload_Click(object sender, EventArgs e)
- {
- loadadata();
- }
- void loadadata()
- {
-
- this.connectdb();
-
- cmd = new SqlCommand(" SELECT lrn, lastname, firstname, middlename, email, username,registereddate from tblOnlineuserregistration where registereddate between '" + TextBox1.Text + "' and '" + TextBox2.Text + "'", cn);
-
-
- dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- this.connectdb();
- cmd = new SqlCommand(" SELECT lrn, lastname, firstname, middlename, email, username,registereddate from tblOnlineuserregistration where registereddate between '" + DateTime.ParseExact(TextBox1.Text, "dd/MM/yyyy", null).ToString("dd/MMM/yyyy") + "' and '" + DateTime.ParseExact(TextBox2.Text, "dd/MM/yyyy", null).ToString("dd/MMM/yyyy") + "'", cn);
- GridView1.DataSource = dr;
- GridView1.DataBind();
- }
- else
- {
- dr.Close();
-
- ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('No record has been found');", true);
- }
- }
- }
- }
