根据从下拉列表中选择的日期显示gridview数据 [英] Displaying the gridview data according to the the selected date from dropdownlist

查看:54
本文介绍了根据从下拉列表中选择的日期显示gridview数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我已经编写了代码,以根据从具有月份列表的下拉列表中选择的月份显示gridview数据.现在,我可以使用特定月份的关联存储过程来获取数据.但是,我想使用相同的下拉列表显示一个月中特定日期的数据.

这是html代码:

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 :

<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" /> 




在这里,我将月份的值作为参数传递给存储的proc,并在从ddl中选择月份后使用按钮"显示数据.
请任何人建议我如何根据从下拉列表中选择的特定月份的特定日期显示数据.

问候,




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,

推荐答案

使用LINQ到数据表并过滤数据.
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



--Pankaj


您还需要使用day参数来修改过程.
我认为您不会使用相同的ddl来过滤当天的记录.也可以使用TextBox或另一个DropDown列表将日期作为参数传递给SP.
除非您传递日期值,否则您将无法获取该特定日期的详细信息.
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.


请在与grid竞标数据的地方共享您的代码.你调试了吗?您是否可以从数据库中获取数据?有3个简单的步骤.
1.在"DropDown List SelectedIndex Changed"上,采用选定的值
2.根据下拉列表中的选定值调用后端数据库.将数据保存在数据集中或任何需要的地方.
3.将其与网格视图绑定.
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.


这篇关于根据从下拉列表中选择的日期显示gridview数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆