如何从选定的月份获取记录 [英] How to get Records from selected month year

查看:48
本文介绍了如何从选定的月份获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于同一个数据库模型类,我想要1个月的2个下拉列表1。当用户选择月份和年份时,只会出现相关的日期记录。

现在我的问题是我不知道如何在下拉列表中仅列出月份和年份以及如何分组记录请帮助我摆脱这种挫折感。

这里是代码。

模型类

I want 2 dropdownlist 1 for month 1 for year both related to same database model class. When user selects month and year only related date records should appear.
Now my problem is that I dont know how to list only month and year in dropdownlist and how to group records please help me out of this frustration.
here is the code.
Model class

namespace BOL1
{
  public  class ADetailsVm
    {
        public List<BOL1.tbl_Transiction> Payables { get; set; }
        public List<BOL1.tbl_Transiction> Reciveables { get; set; }
    }
}
database table (Model)
namespace BOL1
{
    using System;
    using System.Collections.Generic;
    
    public partial class tbl_Transiction
    {
        public int TId { get; set; }
        public Nullable<System.DateTime> Date { get; set; }
        public Nullable<int> AId { get; set; }
        public string TDiscription { get; set; }
        public Nullable<double> PKR { get; set; }
        public Nullable<double> Rate { get; set; }
        public Nullable<double> Amount { get; set; }
        public Nullable<int> TTId { get; set; }
    
        public virtual tbl_Accounts tbl_Accounts { get; set; }
        public virtual tbl_TransictionType tbl_TransictionType { get; set; }
    }
}



控制器


Controller

<pre lang="C#">public ActionResult Index(int accountid)
        {
            ADetailsVm v = new ADetailsVm();
            //Load both the collection properties
            v.Payables = objbs.GetALL().Where(p => p.AId == accountid && p.tbl_TransictionType.Type.Contains("Payable")).ToList();
            v.Reciveables = objbs.GetALL().Where(r => r.AId==accountid && r.tbl_TransictionType.Type.Contains("Reciveable")).ToList();
 
            return View(v);
        }

推荐答案

从记录集的列中获取月份和年份,并将它们转换为可显示的月 - 年字段。

以下代码只是一个模板。你需要写类似的东西。

Get the month and year from the recordset's column and convert them into a displayable month - year field.
The code below is only a template. You will need to write something similar.
foreach (var r in objbs)
{
    cboMonth.Items.Add
    (
       CultureInfo.CurrentCulture.DateTimeFormat.MonthNames.GetValue(r.DateTimeColumn.Month) + " " + r.DateTimeColumn.Year
     );
}


这篇关于如何从选定的月份获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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