Im using VWD 2008 and C#. Im using the code for search data. The seaching is success and no error. But here I want to add is, when the gridview return null value (which means there is no data from search query)...
I want to show label "No Data".
I tried to add this code to the code below:
Expand|Select|Wrap|Line Numbers
- if (gvTicket.DataSource == null)
- //{if (GridView1.DataSource == null)
- {
- lbNodata.Visible = true;
- Label6.Visible = false;
- gvTicket.Visible = false;
- }
- else
- {
- gvTicket.Visible = true;
- Label6.Visible = true;
- }
Expand|Select|Wrap|Line Numbers
- string connectionString = "Data Source=(local);Initial Catalog=DBhelpdesk; User ID=;Password=";
- SqlConnection myConnection = new SqlConnection(connectionString);
- // SELECT * FROM Ticket where " + strSqlParam
- string strSqlParam = "";
- if (CbExactWord.Checked)
- {
- strSqlParam = ddlistColumn.SelectedValue + "='" + txtSearchBox.Text.Trim() + "'";
- }
- else
- {
- strSqlParam = ddlistColumn.SelectedValue + " like '%" + txtSearchBox.Text.Trim() + "%'";
- }
- SqlCommand sql = new SqlCommand("SelectTicketSearch", myConnection);
- sql.CommandType = CommandType.StoredProcedure;
- sql.Parameters.AddWithValue("@strSqlParam", strSqlParam);
- //Response.Write(strSqlParam);
- SqlDataAdapter ad = new SqlDataAdapter(sql);
- DataSet ds = new DataSet();
- ad.Fill(ds, "Ticket");
- gvTicket.DataSource = ds;
- gvTicket.DataBind();
- if (gvTicket.DataSource == null)
- //{if (GridView1.DataSource == null)
- {
- lbNodata.Visible = true;
- Label6.Visible = false;
- gvTicket.Visible = false;
- }
- else
- {
- gvTicket.Visible = true;
- Label6.Visible = true;
- }
-Meshack