Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to dynamic passing Parameter according to selected dropdown values into the query.


ex. If I selected "Birthdate" from the dropdwon then passing query like this
"Select Name, FatherName, Birthdate from Student" and display in the gridview..
Posted
Comments
Venkatesh Mookkan 22-Oct-12 1:58am    
And what you have done so far?
_Amy 22-Oct-12 2:09am    
And? What you tried so far? Where is your dummy code?
Niravvasoya 23-Oct-12 5:57am    
this is .aspx file
--------------------------
<table>
<tr>
<td>

<select id="drpSelect1" runat="server" name="D1">
<option>-- Select --</option>
<option value="BDate">Birth Date</option>
<option value="Mob_No">Mobile no</option>
<option value="F_MobNo">Father Mobile no</option>
<option value="Cat_Id">Catagory</option>
<option value="Str_Id">Stream</option>
</select>
</td>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</td>
</tr>
<tr>
<asp:GridView ID="GridView1" runat="server" BorderWidth="1px" CellPadding="4" ForeColor="Black"
GridLines="Horizontal" BackColor="White" BorderColor="Black"
BorderStyle="None" AllowPaging="True" PageSize="20">
<footerstyle backcolor="#CCCC99" forecolor="Black">
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" BorderColor="Black" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />

</tr>
</table>



this is .aspx.cs file
------------------------
public partial class Admin_Default : System.Web.UI.Page
{
public CommanFunctions co = new CommanFunctions();
public SqlCommand cmd = null;
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
FillGrid();
}
void FillGrid()
{
co.con.Open();
string str1 = "SELECT SurName, Name, FName, BDate FROM Student_Details";
if (drpSelect1.Value == "BDate")
cmd = new SqlCommand(str1, co.con);
DataSet ds1 = new DataSet();
cmd.ExecuteNonQuery();
co.adpt = new SqlDataAdapter(cmd);
co.adpt.Fill(ds1);

GridView1.DataSource = ds1;
GridView1.DataBind();
co.con.Close();
}
}
Niravvasoya 23-Oct-12 6:00am    
and i want "Bdate" pass into the select Query. which is selected from the dropdown menu.

string str1 = "SELECT SurName, Name, FName, BDate FROM Student_Details";

 
Share this answer
 
Comments
Niravvasoya 23-Oct-12 5:52am    
its not working... i am already seen these articles.. but its cant help..
Quote:
according to selected dropdown values into the query

I don't know how you are displaying date of birth is dropdown.

Quote:
I want to dynamic passing Parameter according to selected dropdown values

Suppose your dropdown contains these values:
Name
FatherName 
Birthdate

You can try this:
C#
SqlCommand cmd = new SqlCommand("Select "+DropDown1.SelectedValue+" from Student");


--Amit
 
Share this answer
 
Comments
Niravvasoya 23-Oct-12 5:48am    
yes ......
Niravvasoya 23-Oct-12 6:16am    
you thought is right.. you going right way... help me out... i cant solve this problems...

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