renatois
10-19-2007, 08:26 AM
Hello all, I have a DropDownList that get itīs values from a database and according to the selected value from the DropDownList I want to populate my GridView. Any idea how to do it? Thanks a lot
|
Click to See Complete Forum and Search --> : [RESOLVED] Populate GridView by DropDownList SelectedValue renatois 10-19-2007, 08:26 AM Hello all, I have a DropDownList that get itīs values from a database and according to the selected value from the DropDownList I want to populate my GridView. Any idea how to do it? Thanks a lot renatois 10-19-2007, 01:00 PM SOLUTION BY MAINEONE AT ASP.NET ------------------------------------------------------ If you have a default datasource for your gridview you can modify it on selected index changed event of the drop down. Here is an example if how to modify the select statement, on aspx page(as you can see no select command exists, but when a user is selected in a dropdown the event causes a custom select statement to be added. PAGE............. <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"> </asp:SqlDataSource> I had to convert the string DateTime to DateTime and then reconvert to string with the corret format, so the code goes like this: CODE............................. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string strSQL; strSQL = "SELECT EventoArena.areID, EventoArena.areData, EventoArena.accID, EventoArena.arePontuacao, EventoArena.arePosicao, dbo.Account.ACC_ID_ACCOUNT, dbo.Account.ACC_DS_NICKNAME FROM EventoArena INNER JOIN dbo.Account ON EventoArena.accID = dbo.Account.ACC_ID_ACCOUNT WHERE (EventoArena.areData = '" + Convert.ToDateTime(DropDownList1.SelectedValue).ToString("yyyy-MM-dd") + "') ORDER BY EventoArena.areData DESC, EventoArena.arePosicao"; SqlDataSource1.SelectCommand = strSQL; } Admin@aspsksolutions.com ------------------------------------------------------------- webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |