在 TaskReportPage.aspx 页面中,我有 startdate,enddate,dropdown 和一个下载按钮。
代码如下所示:
<fieldset>
<legend>Enter The Details To Download Report</legend>
<div class="label">
Start Date :<asp:TextBox runat="server" ID="txtStartDate" />
</div>
<div class="label">
End Date:
<asp:TextBox runat="server" ID="txtEndDate"></asp:TextBox>
</div>
<div class="label">
Employee Name:
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="AllRecords">All Records</asp:ListItem>
</asp:DropDownList>
</div>
<div>
<asp:Button ID="btndisplay" runat="server" Text="View Report" OnClick="btndisplay_Click">
</asp:Button>
<asp:Button runat="server" ID="Download" align="center" Text="Download" OnClick="Download_Click">
</asp:Button>
</div>
<div class="value">
<asp:Label ID="lblMessage" runat="server" Visible="false" Style="color: Red"></asp:Label>
</div>
</fieldset>
在 TaskReportPage.aspx.cs 文件中,我可以从 TaskReportPage.aspx 页面获取值。
在后端我有一个包含这些列的表:
Description varchar(500),
CreatedDate datetime,
StatusId int,
UserId int,
Hour int,
Day varchar(10)
我编写了一个用于从数据库中检索值的存储过程,如下所示:
ALTER PROCEDURE [dbo].[RetriveDatatable]
(
@StartDate datetime,
@EndDate datetime,
@Dropdown varchar(50),
@ID INT
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT Day, t.CreatedDate, Description, Hour, Firstname
FROM tbl_TaskType t, tbl_UserDetails u
WHERE t.CreatedDate BETWEEN '@StartDate' AND '@EndDate'
AND u.ID=(SELECT ID FROM tbl_UserDetails WHERE FirstName=@Dropdown);
END
我在 Eye1.designer.cs 文件中导入此存储过程:
此文件遵循实体框架程序。
看起来像:
public int RetriveDatatable(Nullable<global::System.Int32> userID, Nullable<global::System.DateTime> startDate, Nullable<global::System.DateTime> endDate, global::System.String dropdown = dropdowntParameter1)
{
ObjectParameter userIDParameter;
if (userID.HasValue)
{
userIDParameter = new ObjectParameter("UserID", userID);
}
else
{
userIDParameter = new ObjectParameter("UserID", typeof(global::System.Int32));
}
ObjectParameter startDateParameter;
if (startDate.HasValue)
{
startDateParameter = new ObjectParameter("StartDate", startDate);
}
else
{
startDateParameter = new ObjectParameter("StartDate", typeof(global::System.DateTime));
}
ObjectParameter endDateParameter;
if (endDate.HasValue)
{
endDateParameter = new ObjectParameter("EndDate", endDate);
}
else
{
endDateParameter = new ObjectParameter("EndDate", typeof(global::System.DateTime));
}
ObjectParameter dropdowntParameter;
if (dropdown != null)
{
dropdowntParameter = new ObjectParameter("Dropdown", dropdown);
}
else
{
dropdowntParameter = new ObjectParameter("Dropdown", typeof(global::System.String));
}
return base.ExecuteFunction("RetriveDatatable", userIDParameter,startDateParameter, endDateParameter, dropdowntParameter);
}
最后我的问题是我想将 startdate,enddate和dropdown 参数值从 TaskReportPage.aspx.cs 页面发送到 eye1.disigner.cs 文件页面。然后它将调用SP,我从数据库获取数据到 TaskReportPage.aspx.cs 。
请帮帮我.......
答案 0 :(得分:0)
您不应该在设计器文件中编辑任何代码 - 它仅由visual studio生成和使用,最终会被覆盖,您将失去手动更改。请将您添加到设计器文件中的所有代码移动到aspx.cs文件中。