You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Grids/wucGridView2.ascx.cs

106 lines
4.1 KiB
C#

3 years ago
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.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DSWeb.DataAccess;
namespace DSWeb
{
public partial class wucGridView2 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["OrderDire"] = "ASC";
}
}
public void gvBind(string sSQL)
{
string od = "";
if (ViewState["SortOrder"] == null)
{
od = "";
}
else
{
od = " order by " + ViewState["SortOrder"].ToString().Trim() + " " + ViewState["OrderDire"];
}
//
ViewState["gvBind"] = sSQL;
if (od.Trim() != "")
{
sSQL += od;
}
DataSet ds = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, sSQL);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
ViewState["SortOrder"] = e.SortExpression;
if (ViewState["OrderDire"].ToString() == "Desc")
ViewState["OrderDire"] = "ASC";
else
ViewState["OrderDire"] = "Desc";
//
if (ViewState["gvBind"] != null)
{
gvBind(ViewState["gvBind"].ToString());
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//表头
if (e.Row.RowType == DataControlRowType.Header)
{
//单元格变色
foreach (TableCell c in e.Row.Cells)
{
c.Attributes["onmouseover"] = "javascript:bgcolor=this.style.backgroundColor;this.style.backgroundColor='#CDE0FA';";
c.Attributes["onmouseout"] = "javascript:this.style.backgroundColor=bgcolor;";
}
}
//行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//下面两句代码是添加鼠标效果,可以省略,当鼠标移动到行上时,变颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#A7CDF0';");//,this.style.fontWeight='Bold';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
//设置悬浮鼠标指针形状为"小手"
//e.Row.Attributes["style"] = "Cursor:hand";
//单击行选中变色
e.Row.Attributes.Add("onclick ", "if(window.oldtr!=null){window.oldtr.runtimeStyle.cssText='';}this.runtimeStyle.cssText='background-color:#A7CDF0';window.oldtr=this;");//字体变色this.style.color='#FFFFFF';
//e.Row.ForeColor = System.Drawing.Color.White;
//双击该行,弹出详细的信息页面`
string ID = e.Row.Cells[0].Text;
//string ID = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
e.Row.Attributes.Add("OnDblClick", "return openLink('" + ID + "')");
e.Row.ToolTip = "双击该行,显示更详细的信息。";
//e.Row.BackColor = System.Drawing.Color.FromName("#FFE4B5");
e.Row.Attributes.Add("onclick", "selectRow('" + ID + "')");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
//
if (ViewState["gvBind"] != null)
{
gvBind(ViewState["gvBind"].ToString());
}
}
}
}