Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I was doing grid sample...Databind to grid is not displaying though there is no error...Here is the code.


C#
protected void btnSearch_Click(object sender, EventArgs e)
       {
           sqlcon = new SqlConnection(strconn);
           cmd = new SqlCommand("searchCriteriaSP", sqlcon); // calling the stored procedure
           cmd.CommandType = CommandType.StoredProcedure;
           da = new SqlDataAdapter(cmd);
           da.SelectCommand.Parameters.AddWithValue("@input", SqlDbType.VarChar).Value = ddlSearch.SelectedValue; // passing parameter to the procedure to the database
           da.Fill(ds);
           if (ds.Tables[0].Rows.Count > 0)
           {
               GridView1.DataSource = ds;
               GridView1.DataBind();
           }

       }




Any idea...
Posted
Comments
Venkatesh Mookkan 12-Jun-13 23:18pm    
Please update your question with the Store Procedure Definition? That will help us to find the issue easily
Member 9861478 12-Jun-13 23:54pm    
Sure..

Create procedure [dbo].[searchCriteriaSP]
(
@input varchar(250)
)
as
BEGIN
Select * from Employees
where EmployeeName=@input
END
Member 9861478 12-Jun-13 23:55pm    
It is absolutely working....when I use Text box as Search in UI...but not with Dropdown list as search...

1 solution

Try this:
C#
protected void btnSearch_Click(object sender, EventArgs e)
{
   sqlcon = new SqlConnection(strconn);
   cmd = new SqlCommand("searchCriteriaSP", sqlcon); 
   cmd.CommandType = CommandType.StoredProcedure;
   cmd.Parameters.Add(new SqlParameter("@input", SqlDbType.VarChar)).Value = ddlSearch.SelectedValue;
   da = new SqlDataAdapter(cmd);
   da.Fill(ds);
   if (ds.Tables[0].Rows.Count > 0)
   {
       GridView1.DataSource = ds;
       GridView1.DataBind();
   }
}



--Amit
 
Share this answer
 
Comments
Member 9861478 12-Jun-13 23:19pm    
Thank you for your response.still not working..but no error though.
_Amy 12-Jun-13 23:20pm    
That means, there is no data in database related to your search input. Check your related database tables.
Member 9861478 13-Jun-13 0:04am    
It is absolutely working when I use Text box as Search in UI...but not with Dropdown list as search...
_Amy 13-Jun-13 0:06am    
Instead of ddlSearch.SelectedValue here, pass ddlSearch.SelectedItem.Text.
--Amit
Member 9861478 13-Jun-13 0:07am    
Thank you....will try an let you know...Thank you for your patience.

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