Display record not found, if records not exists in gridview, when item selected from dropdownlist
==================================================================================================
Hi frnds,
am working on asp.net c#, sqlserver2005,
on my webpage i have a dropdownlist and a gridview. and 4 textboxes to read the data from database am displaying data in gridview & textboxes according to dropdownlist selected item,
according to dropdownlist if records not exists in gridview. Display a message records not found.
This is my code.
protected void DDLStudents_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conDisp = new SqlConnection(_connString);
SqlCommand cmdDisp = new SqlCommand();
cmdDisp.Connection = conDisp;
cmdDisp.CommandText = "Select * from Student_Records where Student_code ='" + DDLStudents.SelectedValue +"'";
using (conDisp)
{
conDisp.Open();
SqlDataReader readerDisp = cmdDisp.ExecuteReader();
if (readerDisp.Read())
{
TxtPrincipal.Text = readerDisp["Principal"].ToString();
TxtTeacher.Text = readerDisp["Teacher"].ToString();
TxtEmail.Text = readerDisp["Email"].ToString();
TxtTelephone.Text = readerDisp["TelephoneNo"].ToString();
GridBind();
}
else
{
TxtPrincipal.Text = "";
TxtTeacher.Text = "";
TxtEmail.Text = "";
TxtTelephone.Text = "";
}
}
}
public void GridBind()
{
SqlConnection con = new SqlConnection(_connString);
SqlCommand cmd = new SqlCommand("select StudentName,RollNo, FathersName, Standard from Student_Records where Student_code = '" + DDLStudents.SelectedValue + "'", con);
SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
Adpt.Fill(dt);
lblCount.Text = dt.Rows.Count.ToString();
lblCount.Visible = true;
GVView.DataSource = dt;
GVView.DataBind();
}
display a message when records not found in gridview according to dropdownlist.
Note: Gridview will not be displayed when Pageloads. Based on dropdownlist selected item gridview will be displayed.
Please help thanks in advance.