display the data from the database in gridview based on dropdownlist selected value

Posted by Sindhuesh under ASP.NET on 7/9/2013 | Points: 10 | Views : 2180 | Status : [Member] | Replies : 6
Hi,
i have 3 dropdown list . when the user select the value from those dropdown list and click the search button, it should take the dropdown list value and it should display the result database. the query is
select Tname,Mname,timing from Movie m,Theater t,showtime s where( (location='+ DropDownList1.Text+') and
(m.mid=t.mid) and( Mname='+DropDownList.Text+') and (category='+DropDownList3.Text+') and( m.mid=s.mid"));

i need the code to display the above desired result.

Thanks for the help:)




Responses

Posted by: Vuyiswamb on: 7/9/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
This is simple

Break down your problem into small Questions and Ask yourself and Google in between and tell me if you have a problem.


Thank you for posting at Dotnetfunda
[Administrator]

Sindhuesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/9/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Here is how to write your code

SqlConnection con=new SqlConnection(@"Data Source=AOD270\SQLEXPRESS;Initial Catalog=XXXX;User ID=XX;Password=XXXXXXX"); 


string query = "select Tname,Mname,timing from Movie m,Theater t,showtime s where( (location='+ DropDownList1.Text+') and
(m.mid=t.mid) and( Mname='+DropDownList.Text+') and (category='+DropDownList3.Text+') and( m.mid=s.mid")); ";
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);

if(ds.tables[0].rows.count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
response.write("Your Query Returned Nothing");
}
}
catch(SQlException ex)
{
response.writ(ex.Message);
}
finally
{
con.Close();
}


Please show me the html code for your Dropdown



Thank you for posting at Dotnetfunda
[Administrator]

Sindhuesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sindhuesh on: 7/9/2013 [Member] Starter | Points: 25

Up
0
Down
hi, this is my drop down list code.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [location] FROM [place]"></asp:SqlDataSource>

<asp:DropDownList ID="DropDownList1" runat="server" Style="left: 380px; position: absolute;
top: 8px; z-index: 112;" Width="216px" DataSourceID="SqlDataSource1"
DataTextField="location" DataValueField="location">

</asp:DropDownList>



<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [category] FROM [category_type]"></asp:SqlDataSource>

<asp:DropDownList ID="DropDownList3" runat="server"
Style="left: 380px; position: absolute;top: 48px; z-index: 112; width: 216px;"
DataSourceID="SqlDataSource3" DataTextField="category" DataValueField="category">
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Mname] FROM [Movie]"></asp:SqlDataSource>

<asp:DropDownList ID="DropDownList2" runat="server" Style="left: 380px; position: absolute;
top: 88px; z-index: 112; width: 216px;"
DataSourceID="SqlDataSource2" DataTextField="Mname"
DataValueField="Mname">

</asp:DropDownList>
<asp:Button
ID="Button1" runat="server"
style="z-index: 1; left: 381px; top: 183px; position: absolute"
Text="Search" Font-Bold="True" Font-Names="Cambria" Font-Size="14pt"
ForeColor="Maroon" onclick="Button1_Click" />

Thanks for the help:)

Sindhuesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sindhuesh on: 7/9/2013 [Member] Starter | Points: 25

Up
0
Down
i have made the changes as above, but when i clicked the button its not showing any result.

thanks

Sindhuesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/9/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Does your ds bring data ?


Thank you for posting at Dotnetfunda
[Administrator]

Sindhuesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sindhuesh on: 7/9/2013 [Member] Starter | Points: 25

Up
0
Down
the query is correct , but ds doesn't bring the data

Sindhuesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response