Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Dear All,

I have written the code to display the gridview data based on the month selected from a dropdownlist that has list of months in it. Now I am able to get the data using the associated stored procedure for a specific month. But, I want to display the data based on the specific day in a month using the same dropdownlist.

Here's html code :

XML
<tr class="trData">
<td style="text-align: center;">
Select Month
</td>
<td style="text-align: left;">
<asp:DropDownList ID="ddlMonth" runat="server">
<asp:ListItem Text="Jan" Value="1"></asp:ListItem>
<asp:ListItem Text="Feb" Value="2"></asp:ListItem>
<asp:ListItem Text="Mar" Value="3"></asp:ListItem>
<asp:ListItem Text="Apr" Value="4"></asp:ListItem>
<asp:ListItem Text="May" Value="5"></asp:ListItem>
<asp:ListItem Text="June" Value="6"></asp:ListItem>
<asp:ListItem Text="July" Value="7"></asp:ListItem>
<asp:ListItem Text="Aug" Value="8"></asp:ListItem>
<asp:ListItem Text="Sep" Value="9"></asp:ListItem>
<asp:ListItem Text="Oct" Value="10"></asp:ListItem>
<asp:ListItem Text="Nov" Value="11"></asp:ListItem>
<asp:ListItem Text="Dec" Value="12"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<asp:GridView ID="gvOverallReport" runat="server" AutoGenerateColumns="true">  
<pagerstyle cssclass="gridPagerStyle" horizontalalign="Center" width="100%" />
<SelectedRowStyle CssClass="gridSelectedRowStyle" />
<HeaderStyle CssClass="gridHeader" BackColor="#AFB8BF" HorizontalAlign="Left" VerticalAlign="Middle"
BorderColor="#bbbbbb" BorderWidth="1px" Font-Bold="True" ForeColor="White" Font-Size="10pt" />
<alternatingrowstyle backcolor="WhiteSmoke" />
<pagersettings position="TopAndBottom" />
<rowstyle cssclass="grdRow" /> 



here I am passing the the value of a month as a parameter to a stored proc and using the "button" to display the data after selecting the month from ddl.
Please anyone suggest me how to display the data based on the specific day of the specific month selected from dropdownlist.

Regards,
Posted
Updated 3-Mar-11 18:41pm
v4

use LINQ to data table and filter the data.
//dt is data table from store procedure and sDate is date field

var qry=from row in dt.AsEnumerable()
        where row.Field<datetime>("sDate").Day== selectedDayFromDropDown
        select row 
gridview1.DataSource=qry.CopyToDataTable();
</datetime>


--Pankaj
 
Share this answer
 
v2
Comments
pankajupadhyay29 4-Mar-11 0:16am    
I am trying to remove but i am not able to do.
Raj.rcr 4-Mar-11 0:17am    
Sorry, I am not able to understand the code u have provide.. any other idea?
Raj.rcr 4-Mar-11 0:20am    
Actually I am using the "button" to display the data after selecting the month from ddl.
pankajupadhyay29 4-Mar-11 0:21am    
on button click filter the data as i have done in this LINQ.
Raj.rcr 4-Mar-11 0:23am    
I think u r talking about using LINQ namespace. but in my VS edition, there is no LINQ namespace.
You need to modify your procedure with also a day parameter.
I don't think you are going to filter records for the day using the same ddl. Use a TextBox or another DropDown list also to pass the day as parameter to SP.
Unless you pass the day value, you are not going to get the details for that particular day.
 
Share this answer
 
Comments
Raj.rcr 4-Mar-11 1:13am    
Exactly, This is what I needed. Thank you I will try now... and get back in few minutes..
Please share you code where you are biding data with grid . Did you debugged it ? Are you able to fetch data from Database? There are 3 simple step.
1. On DropDown List SelectedIndex Changed, take the selected values
2. Call you backend database based on the selected value for the dropdown list. Save the data in a dataset or where ever you want.
3. Bind it with Grid view.
 
Share this answer
 
Comments
Raj.rcr 4-Mar-11 0:37am    
I am using the second step... where gridview's "autogeneratedcolumns=true" I can provide the stored procedure but its too lengthy.
Raj.rcr 4-Mar-11 0:44am    
I have revised the question. you can now see the gridview..
Abhijit Jana 4-Mar-11 0:55am    
Raj where are you binding it with Gridiview, show me the codebehind code, are you able to debug ? put a breakpoint where you are calling the DB, then see if data is actually getting fetched from DB or not, then check why its not getting binded, are you using GridView.DataBind(), because this is the common mistake happens with gridview.
Raj.rcr 4-Mar-11 0:59am    
I am getting the data based on the specific month selected from dropdwonlist.. there is no problem in that.. But I want the gridview data to b displayed based on the specific day of specific month using the same dropdownlist.. The entire task is depending on the stored proc.. I hope u understand what I am saying..

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