Searching from Userform to Database
I have a webform that keeps an inventory of vehicle maintenance. This form is still in the works, but I am attempting to make it very userfriendly. I need to add a search function so I added a textbox (called textSearch) and a button to push when ready to search. The employee will type the Customer last name into that box, and I need the employee to be redirected to a different userform, and have a datagrid (that is already set-up on the other user form) display all customers with that last name. How would this be done?
Hemant SrivastavaPosted Jan 21, 2013, 2:10 PM
Response.Redirect("SecondPage.aspx?Name=" + txtBx_Request.Text);
And on the second page load, get the query string to populate your data grid. Query string you could get as:
string requested_Name = Request.QueryString["Name"];
richard smithPosted Jan 21, 2013, 5:10 PM
Hemant SrivastavaPosted Jan 21, 2013, 5:00 PM
Hemant SrivastavaPosted Jan 21, 2013, 3:19 PM
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("SecondPage.aspx?Name=" + txtBx_Request.Text);
}
And on the second form page load, get the query string like:
protected void Page_Load(object sender, EventArgs e)
{
string reqName = Request.QueryString["Name"];
if (reqName != "")
{
Label1.Text = "You queried for the person having name: " + reqName;
DataBaseSearch(reqName);
}
}
Now bind your data result into your grid in DataBaseSearch() method
richard smithPosted Jan 21, 2013, 2:34 PM
The name of the method is DatabaseSearch()
richard smithPosted Jan 21, 2013, 1:03 PM
Hemant SrivastavaPosted Jan 21, 2013, 11:27 AM
1. Get the input from 'Search Text Box' (say for last name Smith)
2. Search 'Smith' into your Customer Data collection. If your data collection is already not in memory, bring that data from database. You may use ADO.Net Dataset for reading the data.
Now you have dataset, either store that dataset contents into some .Net collection (e.g. List, Dictionary etc.) then find the word 'smith' OR you can directly search the word in dataset directly by using lambda expression.
(how to searchin dataset, you may refer to this link:
http://www.c-sharpcorner.com/UploadFile/0f68f2/querying-a-data-table-using-select-method-and-lambda-express/)
3. Populate the datagrid with your result set.
4. On 'Search' button click, Redirect to that page on which you are dispalying datagrid.
Hope it could help you.