0

我正在尝试使用类似参数来使用控制参数在我的数据库中的日期字段中获取年份。我需要这个在 aspx 而不是 aspx.cs 页面上工作。下面是我的代码:

<asp:SqlDataSource ID="getStudentResultsYearOne" runat="server"
    ConnectionString="<%$ ConnectionStrings:UniString %>" 
    SelectCommand="SELECT DISTINCT modules.module_name, student_module_grade.grade, module_desc.cat_points,student_module_grade.result_code, student_module_grade.module_grade_id FROM modules INNER JOIN module_on_pathway ON modules.id = module_on_pathway.module_id INNER JOIN module_desc ON modules.id = module_desc.module_id INNER JOIN year_in_pathway ON module_on_pathway.year_in_pathway_id = year_in_pathway.id INNER JOIN pathway_years ON year_in_pathway.pathway_year_id = pathway_years.id INNER JOIN class ON pathway_years.id = class.pathway_year_id INNER JOIN classlist ON class.class_id = classlist.class_id INNER JOIN student_module_grade ON module_on_pathway.id = student_module_grade.module_on_pathway_id INNER JOIN users ON classlist.user_id = users.id INNER JOIN chosen_modules_list ON classlist.classlist_id = chosen_modules_list.classlist_id WHERE (chosen_modules_list.module_on_pathway_id = module_on_pathway.id OR module_on_pathway.mandatory_module = 1) AND module_on_pathway.pathway_year_id = @pathway_years_id AND (year_in_pathway.year_end LIKE '%'+ @maxYear +'%')">


    <SelectParameters>
        <asp:SessionParameter Name="student_id" SessionField="UserLoggedOn" Type="Int32" />
        <asp:ControlParameter Name="pathway_years_id" ControlID="pathwayYearsId" PropertyName="Text" Type="Int32" />
        <asp:ControlParameter Name="maxYear" ControlID="lastYear" PropertyName="Text" Type="String" />
    </SelectParameters>

(这是用于获取当前年份以将其与数据库中的日期进行比较的标签)

<asp:Label ID="lastYear" runat="server" Visible="false"></asp:Label> 

(这是在 .cs 文件中获取当前年份并填充上面提到的标签)

protected void Page_Load(object sender, EventArgs e)
{
    DateTime Today = DateTime.Today;
    Int32 currentYear = Today.Year;

    lastYear.Text = Convert.ToString(currentYear);
}

感谢您的任何帮助,您可以提供。:)

4

0 回答 0