表格分页和高亮显示同时使用时出现问题,如果不分页只是高亮显示没有问题,如果只是分页不高亮显示也没有问题.
错误显示第528行:Ext.get(row).first().addClass('highlight');
前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.highlight
{
background-color:Green;
}
.highlight .x-grid3-col
{
background-image: none;
}
.x-grid3-row-selected .highlight
{
background-color: yellow;
}
.x-grid3-row-selected .highlight .x-grid3-col
{
background-image: none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<xageManager ID="pm_Main" AutoSizePanelID="rpnl_Main" runat="server" FormLabelWidth="1" FormOffsetRight="4px" />
<x:RegionPanel ID="rpnl_Main" ShowBorder="false" runat="server">
<Regions>
<x:Region ID="rgn_Top" Split="true" EnableSplitTip="true" Height="50px" Margins="0 0 0 0" ShowHeader="true" Position="top" runat="server" EnableBackgroundColor="True" ShowBorder="false" Title="待归还的单">
<Items>
<x:Form ID="Form5" ShowBorder="False" BodyPadding="5px" EnableBackgroundColor="true" ColumnWidth="100%" ShowHeader="false" runat="server" Height="75px" >
<Rows>
<x:FormRow ColumnWidths="115px 115px 115px 105px 45px">
<Items>
<x:TextBox ID="txtPartNo" runat="server" ShowLabel="false" EmptyText="编号" Width="110px"></x:TextBox>
<x:TextBox ID="txtName" runat="server" ShowLabel="false" EmptyText="编号" Width="110px"></x:TextBox>
<xropDownList ID="txtApplicant" ShowLabel="false" runat="server" Width="110px"></xropDownList>
<xropDownList ID="txtAppDept" ShowLabel="false" runat="server" Width="100px"></xropDownList>
<x:Button ID="txtSearch" Text="查询" runat="server" ></x:Button>
</Items>
</x:FormRow>
</Rows>
</x:Form>
</Items>
</x:Region>
<x:Region ID="ren_Center" ShowHeader="false" Layout="Fit" Position="Center" Margins="2 2 2 0" runat="server" Title="待审批的单" >
<Items>
<x:Grid ID="Grid1" ShowBorder="false" AutoScroll="true" ShowHeader="false" runat="server" EnableTextSelection="true"
DataKeyNames="id" EnableRowNumber="True"
AllowPaging="true" PageSize="25">
<Columns>
<x:WindowField Width="40px" WindowID="Window1" HeaderText="归还" Text="归还" DataIFrameUrlFields="id,Partno"
DataIFrameUrlFormatString="./P_Return_Submit.aspx?ID={0}&artNo={1}" IFrameUrl="~/alert.aspx"
DataWindowTitleField="id" DataWindowTitleFormatString="Return" />
<x:BoundField Width="80px" DataField="partno" HeaderText="编号" />
<x:BoundField Width="80px" DataField="name" HeaderText="名称" />
<x:BoundField Width="60px" DataField="modelinch" HeaderText="型号(英)" />
<x:BoundField Width="60px" DataField="modelm" HeaderText="型号(公)" />
<x:BoundField Width="40px" DataField="category" HeaderText="类别" />
<x:BoundField Width="60px" DataField="precisionlevel" HeaderText="精度等级" />
<x:BoundField Width="60px" DataField="approveqty" HeaderText="批准数量" />
<x:BoundField Width="80px" DataField="approvedate" DataFormatString="{0:yyyy-MM-dd}" HeaderText="批准日期" />
<x:BoundField Width="80px" DataField="continuedate" DataFormatString="{0:yyyy-MM-dd}" HeaderText="续借日期" />
<x:BoundField Width="50px" DataField="apptype" HeaderText="用途" />
<x:BoundField Width="150px" DataField="appremark" HeaderText="备注" />
<x:BoundField Width="80px" DataField="applicant" HeaderText="申请人" />
<x:BoundField Width="60px" DataField="appdept" HeaderText="申请部门" />
<x:BoundField Width="80px" DataField="appdate" DataFormatString="{0:yyyy-MM-dd}" HeaderText="申请日期" />
</Columns>
</x:Grid>
<x:HiddenField ID="highlightRows" runat="server"> </x:HiddenField>
</Items>
</x:Region>
</Regions>
</x:RegionPanel>
<x:Window ID="Window1" Title="Form" Popup="false" EnableIFrame="true" runat="server"
EnableResize="true" Target="Self" IsModal="True" Width="550px" Height="450px">
</x:Window>
</form>
<script type="text/javascript">
var highlightRowsClientID = '<%= highlightRows.ClientID %>';
var gridClientID = '<%= Grid1.ClientID %>';
function highlightRows() {
var highlightRows = X(highlightRowsClientID);
var grid = X(gridClientID);
grid.el.select('.x-grid3-row table.highlight').removeClass('highlight');
Ext.each(highlightRows.getValue().split(','), function (item, index) {
if (item !== '') {
var row = grid.getView().getRow(parseInt(item, 10));
Ext.get(row).first().addClass('highlight');
}
});
}
// 页面第一个加载完毕后执行的函数
function onReady() {
var grid = X(gridClientID);
grid.addListener('viewready', function () {
highlightRows();
});
}
// 页面AJAX回发后执行的函数
function onAjaxReady() {
highlightRows();
}
</script>
后台代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using FineUI;
public partial class MTMS_P_Return : System.Web.UI.Page
{
SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlMTMS"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == "" | Session["username"] == null)
{
Response.Redirect("../login.aspx?sys=MTMS");
}
if (!IsPostBack)
{
if (!(Session["username"] != "" && Session["username"] != null))
{
Response.Write("<script> window.top.location.href='../login.aspx?sys=MTMS';</script>");
}
string sqlCreator = "select distinct applicant from app_form where status='Out' order by applicant";
string sqlCreateDept = "select distinct appdept from app_form where status='Out' order by appdept";
SqlCommand myCreator = new SqlCommand(sqlCreator, myConnection);
SqlCommand myCreateDept = new SqlCommand(sqlCreateDept, myConnection);
myConnection.Open();
SqlDataAdapter myDataCreator = new SqlDataAdapter(myCreator);
DataTable myDataC = new DataTable();
myDataCreator.Fill(myDataC);
txtApplicant.DataTextField = "Applicant";
txtApplicant.DataValueField = "Applicant";
txtApplicant.DataSource = myDataC;
txtApplicant.DataBind();
txtApplicant.Items.Insert(0, new ListItem("申请人", ""));
SqlDataAdapter myDataCreateDept = new SqlDataAdapter(myCreateDept);
DataTable myDataD = new DataTable();
myDataCreateDept.Fill(myDataD);
txtAppDept.DataTextField = "appDEPT";
txtAppDept.DataValueField = "appDEPT";
txtAppDept.DataSource = myDataD;
txtAppDept.DataBind();
txtAppDept.Items.Insert(0, new ListItem("申请部门", ""));
myConnection.Close();
// loadDetail(" and 1=1 ");
}
else
{
// if (Request.Form["__EVENTTARGET"] == txtPartNo.ClientID && Request.Form["__EVENTARGUMENT"] == "specialkey")
// {
btn_search();
// }
}
loadDetail(" and 1=1 ");
}
protected void btn_SearchClick(object sender, EventArgs e)
{
btn_search();
}
protected void btn_search()
{
string sqlstr1 = "";
if (txtPartNo.Text != "")
{
sqlstr1 += " and a.partno like '%" + txtPartNo.Text + "%'";
}
if (txtName.Text != "")
{
sqlstr1 += " and a.name like '%" + txtName.Text + "%'";
}
if (txtApplicant.SelectedValue != "")
{
sqlstr1 += " and b.Applicant='" + txtApplicant.SelectedText + "'";
}
if (txtAppDept.SelectedValue != "")
{
sqlstr1 += " and b.AppDept='" + txtAppDept.SelectedText + "'";
}
if (sqlstr1 == "")
{
sqlstr1 = " and 1=1 ";
}
// Form5.Reset();
loadDetail(sqlstr1);
}
public void loadDetail(string txtSql) //加载详细项目待审批的单
{
string sqlParts = "";
string sqlStore = "select name from d_admin where name='" + Session["username"].ToString() + "' and role='Store Admin' "; //仓库管理员
SqlCommand cmStore = new SqlCommand(sqlStore, myConnection);
myConnection.Open();
SqlDataReader myStore = cmStore.ExecuteReader();
if (myStore.Read())
{
sqlParts = "select a.partno,a.name,a.modelinch,a.modelm,a.category,a.precisionlevel,b.id,b.appremark,b.apptype,"
+ " b.status,b.applicant,b.appdept,b.appdate,b.approveqty,b.approvedate,b.continuedate from partsinfo a,app_form b "
+ " where a.partno=b.partno and b.status='Out' " + txtSql + " order by b.appdate desc, b.status";
}
else
{
sqlParts = "select a.partno,a.name,a.modelinch,a.modelm,a.category,a.precisionlevel,b.id,b.appremark,b.apptype,"
+ " b.status,b.applicant,b.appdept,b.appdate,b.approveqty,b.approvedate,b.continuedate from partsinfo a,app_form b "
+ " where a.partno=b.partno and b.status='Out' and applicant='" + Session["username"].ToString() + "' order by b.status";
Grid1.Columns[0].Hidden = true;
}
myStore.Close();
SqlCommand myParts = new SqlCommand(sqlParts, myConnection);
SqlDataAdapter mydetail = new SqlDataAdapter(myParts);
DataSet myds = new DataSet();
mydetail.Fill(myds, "partsinfo");
Grid1.DataSource = myds;
Grid1.DataBind();
myConnection.Close();
}
//改变背景颜色
protected void Grid1_RowDataBound(object sender, FineUI.GridRowEventArgs e)
{
DataRowView row = e.DataItem as DataRowView;
if (row != null)
{
DateTime tDelay = DateTime.Now;
if (row["continuedate"].ToString() == "")
{
tDelay = Convert.ToDateTime(row["approvedate"]);
}
else
{
tDelay = Convert.ToDateTime(row["continuedate"]);
}
if (getDays(tDelay) > 6)
{
highlightRows.Text += e.RowIndex.ToString() + ",";
}
}
}
//获取两个日期之间的天数(自定义方法)
protected int getDays(DateTime Adate)
{
DateTime dt1 = Adate; // Convert.ToDateTime("2010-12-06 08:00:00");//初始化一个日期
DateTime dt2 = DateTime.Now; //获取今天日期
System.TimeSpan ts = dt2.Subtract(dt1); //TimeSpan得到dt1和dt2的时间间隔
int countday = ts.Days; //获取两个日期间的总天数
return countday;
}
protected void Grid1_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
btn_search();
}
}
|