Do you wanna get specific record from database by selected item from dropdownlist control. If that what you need please feed me back to tell you how to get that by easy steps whether it will be code or wizard.
regards..
Sincerely,
Mohamed Elzayat Please remember to Mark the replies as Answers if they help.
Facebook
Yes i need specific record from sql database with date
if i select Orthopedics and 22/3/2012 it should display all records of orthopedic related to that date
Ok, bro
Now i will show you simple demo about what you need. Our scenario how to get the orders that has been placed from specific employee. We need to perform that join statement between Employees and Orders tables in NorthWind Database as you see.
SELECT Employees.EmployeeID, Employees.FirstName+' '+Employees.LastName as [Full Name], Orders.OrderID, Orders.OrderDate
FROM Employees INNER JOIN
Orders ON Employees.EmployeeID = Orders.EmployeeID
where Employees.EmployeeID =4 and Orders.OrderDate='1996-07-08'
you could just modify
Mohamed Elzayat's code, it's quite simple,
Mohamed Elzayat's code use dropdownlist selectindexchange event, you can use it in button click event, and disable dropdownlist autopostback.
Abdul Muqeet
Member
82 Points
428 Posts
Search record with Dropdown list and text box
Nov 18, 2012 10:03 AM|LINK
i want to search record with dropdown list and text box
i have fields in dropdown like
1.Orthopedics
2.Clinic
3.Pharmacy
4.ENT
when i select one field and type date in text box i want a list of record submitted on this date with the specific field
Mohamed Elza...
Member
104 Points
17 Posts
Re: Search record with Dropdown list and text box
Nov 18, 2012 10:23 AM|LINK
Hello, bro
Do you wanna get specific record from database by selected item from dropdownlist control. If that what you need please feed me back to tell you how to get that by easy steps whether it will be code or wizard.
regards..
Mohamed Elzayat
Please remember to Mark the replies as Answers if they help.
Facebook
Abdul Muqeet
Member
82 Points
428 Posts
Re: Search record with Dropdown list and text box
Nov 18, 2012 10:48 AM|LINK
Yes i need specific record from sql database with date
if i select Orthopedics and 22/3/2012 it should display all records of orthopedic related to that date
tarunSaini
Contributor
2948 Points
985 Posts
Re: Search record with Dropdown list and text box
Nov 18, 2012 12:04 PM|LINK
its a same issue posted by manav check it your solution
http://www.careersoft-technology.com/forum/?mingleforumaction=viewtopic&t=3.0
RameshRajend...
Star
7983 Points
2099 Posts
Re: Search record with Dropdown list and text box
Nov 18, 2012 12:14 PM|LINK
Hai
You can try this query
select * from TableName where coloumnName =drobdownlistid.selectedvalue and DateTimeColoumn=textbox.Text
Thank you...
Mohamed Elza...
Member
104 Points
17 Posts
Re: Search record with Dropdown list and text box
Nov 18, 2012 01:58 PM|LINK
Ok, bro
Now i will show you simple demo about what you need. Our scenario how to get the orders that has been placed from specific employee. We need to perform that join statement between Employees and Orders tables in NorthWind Database as you see.
SELECT Employees.EmployeeID, Employees.FirstName+' '+Employees.LastName as [Full Name], Orders.OrderID, Orders.OrderDate FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID where Employees.EmployeeID =4 and Orders.OrderDate='1996-07-08'Now let us go to implement that in our demo.
1-First add this tags to source page.
<div> <table class="style1"> <tr> <td class="style2"> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> </asp:DropDownList> </td> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="style2"> </td> <td> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </td> </tr> </table> </div>2- The second step add this to code-behind.
void FillDropDownList() { using (var sqlCon= new SqlConnection("server=.; database=Northwind; integrated security=true")) { using (var sqlCmd= new SqlCommand("select * from employees", sqlCon)) { sqlCon.Open(); using (SqlDataReader sqlReader= sqlCmd.ExecuteReader()) { ListItem li; while (sqlReader.Read()) { li = new ListItem(string.Format("{0} {1}", sqlReader[2], sqlReader[1]), sqlReader[0].ToString()); DropDownList1.Items.Add(li); } DropDownList1.Items.Insert(0, new ListItem("Employee Name")); } } } } void GetAllEmployeeOrders(int empID, string orderDate) { using (var sqlCon = new SqlConnection("server=.; database=Northwind; integrated security=true")) { using (var sqlCmd = new SqlCommand("SELECT Employees.EmployeeID, Employees.FirstName+' '+Employees.LastName as [Full Name],"+ "Orders.OrderID, Orders.OrderDate FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID "+ "where Employees.EmployeeID =@id and Orders.OrderDate=@date", sqlCon)){ sqlCmd.Parameters.AddWithValue("@id",empID); sqlCmd.Parameters.AddWithValue("@date", orderDate); sqlCon.Open(); using (SqlDataReader sqlReader = sqlCmd.ExecuteReader()) { GridView1.DataSource = sqlReader; GridView1.DataBind(); } } } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillDropDownList(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownList1.SelectedIndex != 0 && TextBox1.Text != string.Empty) { GetAllEmployeeOrders(int.Parse(DropDownList1.SelectedValue),TextBox1.Text.Trim()); } }Finally, if you face any problems feel free to ask me again.
Mohamed Elzayat
Please remember to Mark the replies as Answers if they help.
Facebook
Abdul Muqeet
Member
82 Points
428 Posts
Re: Search record with Dropdown list and text box
Nov 20, 2012 09:43 AM|LINK
how can i have your code in btnclick . so that after selecting list from drop down and date how the record will be searched
Elzayat can you explain me something
i am saving the date in data base with every record using year(getdate()) in stored procedure
an it save like 2012-11-20 09:25:50.680 in data base
i am confused how should a user can type full date in text box to search record using date wise ?
20-11-2012
rajish
Member
424 Points
89 Posts
Re: Search record with Dropdown list and text box
Nov 28, 2012 11:30 AM|LINK
you could just modify Mohamed Elzayat's code, it's quite simple, Mohamed Elzayat's code use dropdownlist selectindexchange event, you can use it in button click event, and disable dropdownlist autopostback.