hi , i'm new here :-) , i have textbox with search button the result it's show , but if there is a way to count how many rows was found were cathing the data form database ,,,,
note.
i'm using gridview + ado.net + gridview i handle all the events manually :-)
protected void btnSearch_Click(object sender, EventArgs e) {
if (txtSearch.Text == "") {
lblMessage.Text = "";
lblMessage.Text = "Empty charchter, Try Again";
}
else if(txtSearch.Text!="") {
lblMessage.Text = "";
string connect = ConfigurationManager.ConnectionStrings["Employee_TestConnectionString"].ConnectionString;
string query = "Select EmployeeID,Name,Age,Mobile From Employee where EmployeeID=@EmployeeID";
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand();
try {
SqlDataAdapter da = new SqlDataAdapter(cmd);
int x = GridView1.Rows.Count;
con.Open();
if (Convert.ToInt16(DropCatogry.SelectedValue) == 3) {
txtSearch.Visible = false;
bindgridview();
}
else if (Convert.ToInt16(DropCatogry.SelectedValue) == 1) {
cmd.Parameters.AddWithValue("@EmployeeID", txtSearch.Text);
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
cmd.Connection = con;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
lblMessage.Text= GridView1.Rows.Count.ToString() ;
// lblMessage.Text= ds.Tables.Count.ToString();
if (x == 0) {
lblMessage.Visible = true;
lblMessage.Text = "";
lblMessage.Text += "There Is No Result ,Try Again";
}
else if (x > 0) {
lblMessage.Visible = true;
lblMessage.Text = "";
lblMessage.Text += string.Format("{
0}
Rows Found!", x);
GridView1.DataBind();
}
}
else if (Convert.ToInt16(DropCatogry.SelectedValue) == 2) {
string query2 = "Select EmployeeID,Name,Age,Mobile From Employee where Name like '%" + txtSearch.Text + "%'";
cmd.CommandType = CommandType.Text;
cmd.CommandText = query2;
cmd.Connection = con;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
if (x == 0) {
lblMessage.Visible = true;
lblMessage.Text += "There Is No Result ,Try Again";
}
else if (x > 0) {
lblMessage.Visible = true;
lblMessage.Text += string.Format("{
0}
Row Found!", x);
GridView1.DataBind();
}
}
}
catch (Exception w) {
string msg = "Error";
msg += w.Message;
throw new Exception(msg);
}
finally {
con.Close();
con.Dispose();
}
}
}