Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Populating a GridView with query based on textBox.text in C# and please provide me code behind if possible thanks in advance and help me getiting dis done i am doing hobby school project where a textbox is provided and getting the value from SQL database based on textbox.text and i am doing like result page


friends please help me doing this

thanks in advance

Happy UGADI to all members in advance
Posted

First the requirement is obviously not a good one. User must be aware of the SQL queries very well and should be familiar with the Tables and fields

Second what is the issue here. You have to use the query from the text box in the commandtext while retrieving the datas to data-table or whatever. Then bind it to the GridView.
 
Share this answer
 
v2
Comments
karthikh87 21-Mar-12 9:32am    
this is type of displaying result from sql to gridview and may i know anyother best way to do as you said req is not good one..

and about i am learner so ofcourse this question might be silly m learing sql and .net and i need your support thanks for reply
Vivek.anand34 18-Dec-13 8:19am    
con.open();
sqlcommand cmd=new sqlcommand("select qty,price,unit,rate from Tablename where ProductName='"+ textbox.text+"'",con);
sqldataadopter da=new sqldataadopter(cmd);
datatable dt=new datatable();
da.fill(dt);
gridview1.datasource=dt;
gridview1.databind();
i gave this code but wen i change 'product name' in text box grid values also changes to this product details...
Can't give you the code as you want learn but I can suggest you steps to implement rest is your ability to code:

When submit is clicked get the textbox.text and pass it to dataaccess layer.This is done in .aspx.cs if you are using web.If windows Form.cs

in the data access layer.In the data access layer use SQL command,Connection,Reader objects to fetch data if you want to use connected architecture.Else use SQL command,DataAdapater,Dataset.

Return the dataset to your form.cs or aspx.cs. and assign the datatset.defaultview to the datasource of the grid and call the grid.bind() (in ASP.NET only ).

This displays the data on you page/form

here are the URLS
http://www.dotnetperls.com/datagridview-tutorial[--WinForms]
http://msdn.microsoft.com/en-us/library/aa479341.aspx[--WebForms]

Happy learning :)

Happy ugadi to you too
 
Share this answer
 
v2
Comments
Member 10339457 12-Nov-13 2:44am    
Populating the grid view with text box values using c# can be fount here
http://sharepoint-2010-world.blogspot.in/2013/10/populating-grid-with-form-values.html

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