Click here to Skip to main content
15,030,162 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
   
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.
_Amy 13-Jun-13 0:08am
   
Welcome. :)
Member 9861478 13-Jun-13 0:10am
   
Not working still...I just replaced dropdown with Textbox..Searching criteria is working with Textbox but not with Dropdown
Member 9861478 13-Jun-13 0:10am
   
FYI.. I am getting the values of Dropdown from one of columns in the same table..
_Amy 13-Jun-13 0:18am
   
Checkpoints:
1. Put a breakpoint and check the value of ddlSearch.SelectedItem.Text. It should have it's specific Text.
2. Bind your DropDownList in if(!IsPostBack){....} code block of page load.

--Amit
Member 9861478 13-Jun-13 0:46am
   
Okay. But I have bind the dropdown list directly in the UI..like: There is an option to choose data source.
1. I have checked value with break point and the value is coming up but it is not showing result in the end....
Member 9861478 13-Jun-13 2:44am
   
Please let me know if you need anymore information in this concern. I am sorry for my ignorance....if I don't make any sense in this situation...

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