Thanks Very Much valkyrie, that worked a treat.
Main Topics
Browse All TopicsI have a gridview that shows data from sql using a query. The query find the current month and year and displays cases for the current month. I have added two dropdownlists to my page. These are unbound. The first dropdownlist has the months in number format (01, 02, 03 etc). The second dropdownlist has the year which is worked with vb.net to add current year and three years previous (2007, 2006, 2005, 2004). I would like to be able to set the two dropdownlists to a month and year and have the gridview automatically change and show the cases for that month and year.
I cant figure out how to tie the dropdownlists to the query for unbound dropdownlists.
The code i have just now is -
VB.NET
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblmonth.Text = DateTime.Now.ToString("MMM
If Not Page.IsPostBack Then
Call Populate_MonthList()
Call Populate_YearList()
End If
End Sub
Sub Populate_MonthList()
'Add each month to the list
drpmonth.Items.Add("01")
drpmonth.Items.Add("02")
drpmonth.Items.Add("03")
drpmonth.Items.Add("04")
drpmonth.Items.Add("05")
drpmonth.Items.Add("06")
drpmonth.Items.Add("07")
drpmonth.Items.Add("08")
drpmonth.Items.Add("09")
drpmonth.Items.Add("10")
drpmonth.Items.Add("11")
drpmonth.Items.Add("12")
'Make the current month selected item in the list
drpmonth.Items.FindByValue
End Sub
Sub Populate_YearList()
Dim intYear As Integer
'Year list can be changed by changing the lower and upper
'limits of the For statement
For intYear = DateTime.Now.Year - 3 To DateTime.Now.Year
drpyear.Items.Add(intYear)
Next
'Make the current year selected item in the list
drpyear.Items.FindByValue(
End Sub
End Class
ASP.NET
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm
<html xmlns="http://www.w3.org/1
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="text-align: left">
<form id="form1" runat="server">
<div style="text-align: center"> <asp:Label ID="lblmonth" runat="server" Font-Names="Verdana" Font-Size="14pt"></asp:Lab
<br />
<br />
<asp:DropDownList ID="drpmonth" runat="server" Font-Names="Verdana" Font-Size="12pt" AutoPostBack="True">
</asp:DropDownList>
<asp:DropDownList ID="drpyear" runat="server" Font-Names="Verdana" Font-Size="12pt" AutoPostBack="True">
</asp:DropDownList><br />
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BC_BE_Ac
SelectCommand="SELECT Lender.Company, COUNT(CaseProcessing.Statu
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
Width="850px">
<Columns>
<asp:BoundField DataField="Company" HeaderText="Company" HtmlEncode="False" SortExpression="Company">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="330px" />
</asp:BoundField>
<asp:BoundField DataField="Completed" HeaderText="Completed" ReadOnly="True" SortExpression="Completed"
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="130px" />
</asp:BoundField>
<asp:BoundField DataField="Comm In" DataFormatString="{0:C}" HeaderText="Comm In"
HtmlEncode="False" ReadOnly="True" SortExpression="Comm In">
<ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="130px" />
</asp:BoundField>
<asp:BoundField DataField="Comm Out" DataFormatString="{0:C}" HeaderText="Comm Out"
HtmlEncode="False" ReadOnly="True" SortExpression="Comm Out">
<ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="130px" />
</asp:BoundField>
<asp:BoundField DataField="Comm Net" DataFormatString="{0:C}" HeaderText="Comm Net"
HtmlEncode="False" ReadOnly="True" SortExpression="Comm Net">
<ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Width="130px" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: valkyrie_ncPosted on 2007-11-05 at 07:17:08ID: 20216684
You should be able to accomplish this by using parameters in your SqlDataSource.
cessConnec tionString %>" SelectCommand="SELECT Lender.Company, COUNT(CaseProcessing.Statu sID) AS Completed, SUM(vw_Case_CommissionTota l.Commissi onIn) AS [Comm In], SUM(vw_Case_CommissionTota l.Commissi onOut) AS [Comm Out], SUM(vw_Case_CommissionTota l.Commissi onNet) AS [Comm Net] FROM CaseDetails INNER JOIN CaseProcessing ON CaseDetails.CaseID = CaseProcessing.CaseID INNER JOIN CaseUnderWriting ON CaseDetails.CaseID = CaseUnderWriting.CaseID INNER JOIN Lender ON CaseUnderWriting.LenderID = Lender.ID INNER JOIN vw_Case_CommissionTotal ON CaseProcessing.CaseID = vw_Case_CommissionTotal.ca seid WHERE (MONTH(CaseProcessing.Stat usDate) = @SelectMonth) AND (YEAR(CaseProcessing.Statu sDate) = @SelectYear) AND (CaseDetails.LoanTypeID = 8) AND (CaseProcessing.StatusID = 22) GROUP BY Lender.Company ORDER BY Lender.Company"> e"/> e"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BC_BE_Ac
<SelectParameters>
<asp:controlparameter name="SelectMonth" controlid="drpmonth" propertyname="SelectedValu
<asp:controlparameter name="SelectYear" controlid="drpyear" propertyname="SelectedValu
</SelectParameters>
</asp:SqlDataSource>
hth
valkyrie_nc