Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Sir,

I am Rakesh P.

I have a simple issue about Gridview and Textbox .

I have table "EMP" in database. now I have textbox and button & Gridview ON PAGE

I want to display result for particular empid in gridview when i enter empid in text box . I tried to implement it by using where clause but it shows error that textbox can't bound with gv


Please help me ...


-Rakesh
Posted
Comments
Karthik Harve 16-Jul-12 9:03am    
Can you show your code?
Sandeep Mewara 16-Jul-12 9:59am    
Why a repost:
http://www.codeproject.com/Questions/422368/Gridview-and-Textbox-by-using-where-condition

Please refer following threads:

This thread will show you how to search through all columns of ASP.NET GridView Data and show only those data which satisfies the search text: How to search through GridView records[^]

This example describes how to use GridView Filtering or Filter Gridview with DropDownList: GridView Filter Expression with DropDownList ASP.NET[^]

ASP.NET GridView Filtering[^]

Also have a look on this CP Article, this will give you a Custom control derived from GridView, implements filtering, custom Top pager, and custom Bottom pager.
Custom GridView with Paging and Filtering[^]

..and some more:
Filterable Grid for ASP.NET[^]
ASP.NET GridView with search option (SearchableGridView)[^]

Display Large Amount of Data in GridView with Search Functionality[^]
ASP.NET GridView with search option (SearchableGridView)[^]
GridView Multiple Filter AJAX Control[^]
 
Share this answer
 
Comments
[no name] 16-Jul-12 9:37am    
I have implemented like this.....what is wrong in this


protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection Cn = new SqlConnection("server=OM-PC;database=master;uid=SA;pwd=123");

SqlCommand Cmd = new SqlCommand("SELECT * FROM DEPT WHERE TextBox1.Text= DNO", Cn);
Cn.Open();

SqlDataReader Dr = Cmd.ExecuteReader();

GridView1.DataSource = Dr;
GridView1.DataBind();

Dr.Close();

Cn.Close();


}
}
Hi ,
Check this
how to search the records using textbox[^]
Best Regards
M.Mitwalli
 
Share this answer
 
Hi Rectus,

Please try like this

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection Cn = new SqlConnection("server=OM-PC;database=master;uid=SA;pwd=123");
        
        string query="SELECT * FROM DEPT WHERE DNO="+ Convert.ToInt32(TextBox1.Text);

        //if your department number contains any character 
        string query="SELECT * FROM DEPT WHERE DNO='"+ Convert.ToInt32(TextBox1.Text)+"'";

        SqlCommand Cmd = new SqlCommand(query, Cn);
        Cn.Open();
        SqlDataReader Dr = Cmd.ExecuteReader();
        GridView1.DataSource = Dr;
        GridView1.DataBind();
        Dr.Close();
        Cn.Close();

    }
}


I hope this will help you in your problem. Please make it resolved if it helps you.

Thanks and Regards
Suman Zalodiya
 
Share this answer
 

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