I am trying to display results based on both dropdown list selection.If a user selects Jan from 1st ddl and 2013 from 2ns ddl then results of Jan 2013 will be displayed to the user,everything works fine,I wanted to confirm the query that I have used is correct or not.
Store Procedure
Create proc usp_monthwisedata
@month int,
@year int
as
begin
select id,balance,datepart(mm,Date)Mnth from tblDailyReport where datepart(mm,Date)=@month and datepart(yy,Date)=@year
end
Design
<asp:DropDownList ID="ddlmonth" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem Selected="True" Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="1">Jan</asp:ListItem>
<asp:ListItem Value="2">Feb</asp:ListItem>
<asp:ListItem Value="3">Mar</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="12">Dec</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlyear" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem Selected="True" Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="2013">2013</asp:ListItem>
<asp:ListItem Value="2014">2014</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView2" runat="server" EmptyDataText="Nothing selected"
AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Balance" HeaderText="Name"/>
</Columns>
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
Code Behind
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string cn = ConfigurationManager.ConnectionStrings["connectivity"].ConnectionString;
using (SqlConnection connection = new SqlConnection(cn))
{
SqlCommand command = new SqlCommand("usp_monthwisedata", connection);
connection.Open();
command.Parameters.AddWithValue("@month", ddlmonth.SelectedValue);
command.Parameters.AddWithValue("@year", ddlyear.SelectedValue);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = command.ExecuteReader();
GridView2.DataSource = dr;
GridView2.DataBind();
}
}
My concerns are:
1.Is the way of writing the Sp is correct to achieve the result.
2.Is it correct to set the onselectedindexchanged of both the ddls to 1 method i.e onselectedindexchanged="DropDownList1_SelectedIndexChanged"
3.Over all Performance wise is it correct.
4.Any other solution is appreciated.