FineUI 官方论坛
标题:
按日期范围查询数据绑定到GRID出错,第一次查没有问题
[打印本页]
作者:
treedun
时间:
2013-11-20 11:16
标题:
按日期范围查询数据绑定到GRID出错,第一次查没有问题
<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="hello.aspx.cs" Inherits="EmptyProjectNet40.hello" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link href="../css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<x:PageManager ID="PageManager1" runat="server" />
<x:DatePicker runat="server" Label="开始日期" EmptyText="开始日期" ID="dp_start_date"> </x:DatePicker>
<x:DatePicker runat="server" Label="结束日期" EmptyText="结束日期" ID="dp_end_date"> </x:DatePicker>
<x:Button ID="btn_search" CssClass="btn-in-form" runat="server" Icon="ApplicationGo"
Text="查询数据" OnClick="btn_search_Click" EnableAjax="false" DisableControlBeforePostBack="false"></x:Button>
<x:Grid ID="Grid2" Title="RM进口数据" PageSize="80" ShowBorder="false" AllowPaging="true"
ShowHeader="False" runat="server" EnableCheckBoxSelect="False"
DataKeyNames="Id" EnableRowNumber="True" IsDatabasePaging="true" OnPageIndexChange="Grid2_PageIndexChange"
EnableMultiSelect="false" EnableRowSelectEvent="true" AllowSorting="true" SortColumnIndex="0"
SortDirection="DESC" OnSort="Grid2_Sort">
<Columns>
<x:BoundField Width="20px" DataField="id" SortField="id" DataFormatString="{0}" HeaderText="id" Hidden="True" HideMode="Offsets" />
<x:BoundField Width="150px" DataField="rm_ieguandanhao" SortField="rm_ieguandanhao" DataFormatString="{0}" HeaderText="报关单号" />
</Columns>
</x:Grid>
</form>
</body>
</html>
复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI.Examples;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using FineUI;
using System.Text;
namespace EmptyProjectNet40
{
public partial class waihuishuju : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Panel7.Title = "外汇数据 (默认显示本月的数据)- 页面加载时间:" + DateTime.Now.ToLongTimeString();
DateTime now = DateTime.Now;
DateTime d1 = new DateTime(now.Year, now.Month, 1);
DateTime d2 = d1.AddMonths(1).AddDays(-1);
dp_start_date.Text = d1.ToString("yyyy-MM-dd");
dp_end_date.Text = d2.ToString("yyyy-MM-dd");
//BindGrid();
}
}
/// <summary>
/// 默认显示本月
/// </summary>
protected void BindGrid()
{
string dsd = dp_start_date.Text.Trim();
string ded = dp_end_date.Text.Trim();
// if (dsd == "" && ded == "")
// {
//全部显示为正数
// BindPageDB(Grid2, Conn_zhangcehexiao
// , string.Format(@"select id,rm_ieguandanhao,rm_bizhi,
// CASE WHEN rm_zongjin_e<0 THEN -rm_zongjin_e
// ELSE rm_zongjin_e
// END
// AS 'rm_zongjin_e',rm_maoyifangshi,rm_shenbaoriqi,
// rm_hetonghao,rm_qiyunguo,rm_chengjiaofangshi from RM_jinkou
// WHERE datediff(month, rm_shenbaoriqi,getdate())=0")
// , "select count(*) from RM_jinkou WHERE datediff(month, rm_shenbaoriqi,getdate())=0");
// BindPageDB(Grid1, Conn_zhangcehexiao
// , string.Format(@"select id,fg_ieguandanhao,fg_bizhi,
// CASE WHEN fg_zongjin_e<0 THEN -fg_zongjin_e
// ELSE fg_zongjin_e
// END
// AS 'fg_zongjin_e',fg_maoyifangshi,fg_shenbaoriqi,
// fg_kehudingdanhao,fg_yundiguo,fg_chengjiaofangshi from FG_chukou
// WHERE datediff(month, fg_shenbaoriqi,getdate())=0")
// , "select count(*) from FG_chukou WHERE datediff(month, fg_shenbaoriqi,getdate())=0");
// }
// else if (dp_start_date.Text.Trim() != "" && dp_end_date.Text.Trim() != "")
// {
BindPageDB(Grid2, Conn_zhangcehexiao, string.Format(@"select id,rm_ieguandanhao,rm_bizhi,
CASE WHEN rm_zongjin_e<0 THEN -rm_zongjin_e
ELSE rm_zongjin_e
END
AS 'rm_zongjin_e',rm_maoyifangshi,rm_shenbaoriqi,
rm_hetonghao,rm_qiyunguo,rm_chengjiaofangshi from RM_jinkou
WHERE rm_shenbaoriqi BETWEEN '{0}' AND '{1}'", dsd, ded)
, string.Format(@"select count(*) from RM_jinkou WHERE rm_shenbaoriqi BETWEEN '{0}' AND '{1}'", dsd,ded));
BindPageDB(Grid1, Conn_zhangcehexiao
, string.Format(@"select id,fg_ieguandanhao,fg_bizhi,
CASE WHEN fg_zongjin_e<0 THEN -fg_zongjin_e
ELSE fg_zongjin_e
END
AS 'fg_zongjin_e',fg_maoyifangshi,fg_shenbaoriqi,
fg_kehudingdanhao,fg_yundiguo,fg_chengjiaofangshi from FG_chukou
WHERE fg_shenbaoriqi BETWEEN '{0}' AND '{1}'", dsd, ded)
, string.Format(@"select count(*) from FG_chukou WHERE fg_shenbaoriqi BETWEEN '{0}' AND '{1}'", dsd, ded));
//}
}
#region 排序和翻页
protected void Grid2_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
{
Grid2.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void Grid2_Sort(object sender, FineUI.GridSortEventArgs e)
{
Grid2.SortDirection = e.SortDirection;
Grid2.SortColumnIndex = e.ColumnIndex;
BindGrid();
}
protected void Grid1_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void Grid1_Sort(object sender, FineUI.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortColumnIndex = e.ColumnIndex;
BindGrid();
}
#endregion
/// <summary>
/// 按日期范围查找
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_search_Click(object sender, EventArgs e)
{
string dsd = dp_start_date.Text.Trim();
string ded = dp_end_date.Text.Trim();
if (dsd!="" && ded!="")
{
BindGrid();
}
else
{
Alert.Show("日期不能为空:(");
}
}
protected void btn_excel_fg_Click(object sender, EventArgs e)
{
ExcelExport(Grid1, "外汇数据_FG出口",true);
}
protected void btn_excel_rm_Click(object sender, EventArgs e)
{
ExcelExport(Grid2, "外汇数据_RM进口",true);
}
}
}
复制代码
作者:
treedun
时间:
2013-11-20 14:16
没办法,三石老大有空帮看下吧,我用其它方法解决了,如下图
[attach]3710[/attach]
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4