在管理系统中常用的 文本框弹出选择框 自定义控件(1)

图:2011030703340578.png

2011030703360871.png

要求:

1,弹出框可以是定义好的样式,如上图,有搜索板面和被选择列表,也可以是自由页面

2,显示的列数据为可配置

3,搜索的列数据为可配置

4,可以在弹出框中进行查询

5,在弹出框中的列表进行分页

6,选中后返回TEXT/VALUE键值对

7,选中后可以返回同页面其它控件需要的值

8,弹出框里的数据为可配置

9,支持jquery表单验证插件

10,支持在选中后触发客户端事件

11,支持在选中后触发服务器端事件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace CustomControl
{
[
AspNetHostingPermission(SecurityAction.Demand,
Level
= AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level
= AspNetHostingPermissionLevel.Minimal),
DefaultProperty(
" Text " ),
ToolboxData(
" <{0}:TextBoxSelect runat=\"server\"> </{0}:TextBoxSelect> " )
]
[ToolboxBitmap(
@" G:\承接项目\南宁雨龙塑业有限公司\YLERP\CustomControl\Resources\Icons\TextBoxSelect.png " )]

public class TextBoxSelect : CompositeControl
{
#region Value Property
/// <summary>
/// Control Text
/// </summary>
public string Text
{
get
{
if (txt == null )
return String.Empty;
return txt.Text;
}
set { txt.Text = value; }
}
/// <summary>
/// Control Value
/// </summary>
public string Value
{
get
{
if (hidden == null )
return String.Empty;
return hidden.Value;
}
set { hidden.Value = value; }
}
#endregion
#region Appearance Property
/// <summary>
/// TextBox Css
/// </summary>
public string TextBoxClass
{
get
{
object o = ViewState[ " TextBoxClass " ];
if (o == null )
return String.Empty;
return ( string )o;
}
set { ViewState[ " TextBoxClass " ] = value; }
}
/// <summary>
/// Image Button Css
/// </summary>
public string ImageButtonClass
{
get
{
object o = ViewState[ " ImageButtonClass " ];
if (o == null )
return String.Empty;
return ( string )o;
}
set { ViewState[ " ImageButtonClass " ] = value; }
}
#endregion
#region OpenWindow Property
/// <summary>
/// Dialog Mode Default or Custom
/// </summary>
public DialogModes DialogMode
{
get
{
object o = ViewState[ " DialogMode " ];
if (o == null )
return DialogModes.Default;
return (DialogModes)o;
}
set { ViewState[ " DialogMode " ] = value; }
}
/// <summary>
/// Dialog Url(If DialogMode equal Default then the url is /UserControl/TextBoxSelectDialogDefault.aspx
/// else is the value of this property)
/// </summary>
public string DialogUrl
{
get
{
object o = ViewState[ " DialogUrl " ];
if (o == null )
return string .Empty;
return ( string )o;
}
set { ViewState[ " DialogUrl " ] = value; }
}
/// <summary>
/// XML DataKey
/// </summary>
public string DataKey
{
get
{
object o = ViewState[ " DataKey " ];
if (o == null )
return string .Empty;
return ( string )o;
}
set { ViewState[ " DataKey " ] = value; }
}
/// <summary>
/// Being set value controls's ID separates with ","
/// Note: the control has to contain "value" property in the HTML DOM
/// </summary>
public string SetValueControlIDList
{
get
{
object o = ViewState[ " SetValueControlIDList " ];
if (o == null )
return string .Empty;
return ( string )o;
}
set { ViewState[ " SetValueControlIDList " ] = value; }
}
/// <summary>
/// The field in database data will be set to controls,which separate with ","
/// </summary>
public string SetValueControlFieldList
{
get
{
object o = ViewState[ " SetValueControlFieldList " ];
if (o == null )
return string .Empty;
return ( string )o;
}
set { ViewState[ " SetValueControlFieldList " ] = value; }
}
#endregion
#region Validation Property
public RegexEnum ValType
{
get
{
object o = ViewState[ " ValType " ];
if (o == null )
return RegexEnum.Null;
return (RegexEnum)o;
}
set { ViewState[ " ValType " ] = value; }
}
public string ValMsg
{
get
{
object o = ViewState[ " ValMsg " ];
if (o == null )
return string .Empty;
return ( string )o;
}
set { ViewState[ " ValMsg " ] = value; }
}
#endregion
public TextBoxSelect()
{
txt
= new TextBox();
hidden
= new HiddenField();

}
protected override void OnPreRender(EventArgs e)
{
base .OnPreRender(e);
Page.ClientScript.RegisterClientScriptResource(
this .GetType(), " CustomControl.Resources.Scripts.TextBoxSelect.js " );
Style.Add(HtmlTextWriterStyle.WhiteSpace,
" nowrap " );
if ( ! DesignMode)
Page.Trace.Write(
" OnPreRender " );
}
protected override void CreateChildControls()
{
Controls.Clear();
CreateControlHierarchy();
ClearChildViewState();
}
private HiddenField hidden;
private TextBox txt;
protected virtual void CreateControlHierarchy()
{

Panel container
= new Panel();

txt.ID
= " text " ;
txt.Text
= this .Text;
if (TextBoxClass != string .Empty)
{
txt.CssClass
= TextBoxClass;
}
else
{
txt.CssClass
= " textbox " ;
}
if (Width != 0 ) txt.Width = Width;


hidden.Value
= Value;
hidden.ID
= " value " ;
Button btn
= new Button();
btn.Text
= " ... " ;
btn.ID
= " btn " ;
string strJS = string .Empty;
if (DialogMode == DialogModes.Default)
{
// function ShowDialog(url,SetValueControlIDList, SetValueControlFieldList,this.ClientID)
strJS = string .Format( " javascript:return ShowDialog('{0}?key={1}','{2}','{3}','{4}'); " ,
" /UserControl/TextBoxSelectDialogDefault.aspx " , DataKey, SetValueControlIDList, SetValueControlFieldList, this .ClientID);
}
else if (DialogMode == DialogModes.Custom)
{
strJS
= string .Format( " javascript:return ShowDialog('{0}','{1}','{2}','{4}'); " ,
DialogUrl, DataKey, SetValueControlIDList, SetValueControlFieldList,
this .ClientID);
}
btn.OnClientClick
= strJS;
if (ValType != RegexEnum.Null && ValMsg != string .Empty)
{
txt.Attributes.Add(
" ValType " , ValType.ToString());
txt.Attributes.Add(
" ValMsg " , ValMsg);
}
txt.Attributes.Add(
" ondblclick " , strJS);
txt.Attributes.Add(
" onkeydown " , " return false; " );
txt.Attributes.Add(
" onpaste " , " return false; " );
if (ImageButtonClass != string .Empty)
{
btn.CssClass
= ImageButtonClass;
}
else
{
btn.CssClass
= " TextBoxSelectImage " ;
}
Controls.Add(txt);
Controls.Add(hidden);
Controls.Add(btn);
if ( ! DesignMode )
Page.Trace.Write(
" CreateChildControls " );
}
}
public enum DialogModes { Default, Custom }
public enum RegexEnum { Null, NotNull, Int, IntOrNull, Num, NumOrNull, Date, Email, QQ, Chinese }
}

function ShowDialog(Url, SetValueControlIDList, SetValueControlFieldList,controlID) {
//SetValueControlIDList:要设置的其它控件ID,以“,”分隔
//SetValueControlFieldList:控件数据的数据库表字段名,以“,”分隔
if (Url == undefined || Url == "" ) { alert( " Url为空或者不存在检查DialogUrl属性! " ); return false ; }
var idArray;
var fieldArry;
if (SetValueControlIDList != "" && SetValueControlFieldList != "" ) {
idArray
= SetValueControlIDList.split( " , " );
fieldArry
= SetValueControlFieldList.split( " , " );
if (idArray.length != fieldArry.length) {
alert(
" 要设置的控件ID数和数据库字段数不同,请检查! " );
return false ;
}
}
var arguments = {};
arguments.url
= Url;
arguments.setValueControlFieldList
= SetValueControlFieldList;
var returnValue = window.showModalDialog( " /UserControl/TextBoxSelectDialogDefaultFrame.aspx " , arguments,
" scroll:yes;center:yes;help:no;resizable:yes;status:no;dialogWidth:530px;dialogHeight:490px " );
if ( ! returnValue) { alert( " returnValue is null! " ); return ; }
$(
" # " + controlID + " _value " ).attr( " value " , returnValue[ 0 ]);
$(
" # " + controlID + " _text " ).attr( " value " , returnValue[ 1 ]);
if (idArray) {
if (idArray.length == returnValue.length - 2 ) {
for ( var i = 0 ; i < idArray.length; i ++ ) {
$(
" # " + idArray[i]).attr( " value " , returnValue[i + 2 ]);
}
}
else {
alert(
" Return columns number was not correct! " + idArray.length + returnValue.length);
}
}
return false ;
}
这是前一篇里嵌入的JS资源文件源码

因为在showModalDialog中的超链和回发都会弹出自己本身的窗体,所以加个IFRAME页面:TextBoxSelectDialogDefaultFrame.aspx

无后台代码

< iframe name = " mainIFrame " id = " mainIFrame " height = " 490px " width = " 100% " border = " 0 " frameborder = " 0 " >
< / iframe>
< script type = " text/jscript " >
var p = window.dialogArguments;
$(
" #mainIFrame " ).attr( " src " , p.url);
< / script>

IFRAME里装载的才是真正的弹出窗页面:

< asp:Panel runat = " server " ID = " panelSearch " >
< table cellspacing = " 1 " align = " center " class = " Table " >
< tr >
< td width = " 10% " class = " TDTitle " >
搜索关键字:
< / td>
< td width = " 20% " class = " TDCtrl " >
< asp:TextBox ID = " txtKeyWord " CssClass = " textbox " runat = " server " >< / asp:TextBox>
< / td>
< td class = " TDNote " >
< asp:Label runat = " server " ID = " lbDescription " Text = " 解释 " >< / asp:Label>
< / td>
< / tr>
< tr >
< td class = " TDCtrl " style = " padding: 5px 0px 5px 10px; " colspan = " 3 " >
< asp:Button ID = " btnSearch " runat = " server " CssClass = " button " Text = " 查询 " OnClick = " btnSearch_Click " / >
< / td>
< / tr>
< / table>
< / asp:Panel>
< br / >
< asp:GridView runat = " server " ID = " GridView1 " AllowPaging = " false " AutoGenerateColumns = " false "
Width
= " 99% " BorderWidth = " 0 " CellPadding = " 0 " CellSpacing = " 1 " BackColor = " #c0de98 "
HorizontalAlign
= " Center " OnRowDataBound = " GridView1_RowDataBound " >
< / asp:GridView>
< table width = " 100% " border = " 0 " cellspacing = " 0 " cellpadding = " 0 " >
< tr >
< td align = " center " valign = " bottom " height = " 30px " >
< div style = " width: 95%; " class = " STYLE1 " >
< webdiyer:AspNetPager CssClass = " aspnetpager " ID = " AspNetPager1 " HorizontalAlign = " Right "
OnPageChanging
= " AspNetPager1_PageChanging " runat = " server " ShowPageIndex = " false "
ShowPageIndexBox
= " Always " SubmitButtonImageUrl = " ../Resources/Images/AspNetPager/go.gif "
AlwaysShow
= " true " ImagePath = " ../Resources/Images/AspNetPager/ " ButtonImageNameExtension = " n "
ButtonImageExtension
= " .gif " DisabledButtonImageNameExtension = " g " CpiButtonImageNameExtension = " r "
PagingButtonType
= " Image " PageIndexBoxClass = " indexbox " CustomInfoHTML = " 共%RecordCount%条纪录,当前第%CurrentPageIndex%/%PageCount%页,每页%PageSize%条记录 "
ShowCustomInfoSection
= " Left " CustomInfoTextAlign = " Left " >
< / webdiyer:AspNetPager>
< / div>
< / td>
< / tr>
< / table>
< script type = " text/jscript " >
var selectedRow;
function SelectRow(id) {
var tbl = $(id)[ 0 ];
if (tbl) {
for ( var i = 1 ; i < tbl.rows.length; i ++ ) {
tbl.rows[i].onmouseover
= function () {
if ( this != selectedRow) {
for ( var j = 0 ; j < this .cells.length; j ++ ) {
this .cells[j].style.backgroundColor = " #EDF1E8 " ;
}
}
}
tbl.rows[i].onmouseout
= function () {
if ( this != selectedRow) {
for ( var j = 0 ; j < this .cells.length; j ++ ) {
this .cells[j].style.backgroundColor = " #FFFFFF " ;
}
}
}
tbl.rows[i].onclick
= function () {
if (selectedRow) {
for ( var j = 0 ; j < selectedRow.cells.length; j ++ ) {
selectedRow.cells[j].style.backgroundColor
= " #FFFFFF " ;
}
}
for ( var j = 0 ; j < this .cells.length; j ++ ) {
this .cells[j].style.backgroundColor = " #86A752 " ;
}
selectedRow
= this ;
}
tbl.rows[i].ondblclick
= function () {
var fields = " <%=xmlModel.ValueTextFields %> " ;
if (window.parent.p.setValueControlFieldList != "" ) {
fields
= fields + ' , ' + window.parent.p.setValueControlFieldList;
}
var fieldArray = fields.split( ' , ' );
var idPre = " <%=GridView1.ClientID %>_ " ;
var resArray = new Array();
for ( var i = 0 ; i < fieldArray.length; i ++ ) {
for ( var j = 0 ; j < this .cells.length; j ++ ) {
if (idPre + fieldArray[i] == tbl.rows[ 0 ].cells[j].id) {
resArray.push(i.toString()
+ " :\" " + this .cells[j].innerText + " \" " );
break ;
}
if (j == this .cells.length - 1 ) {
alert(
" The field of " + fieldArray[i] + " was not found! " );
return ;
}
}
}

window.parent.returnValue
= eval( ' ({ ' + resArray.join( ' , ' ) + ' }) ' );
window.parent.returnValue.length
= resArray.length;
// debugger;
window.parent.close();
}
}
}
}
$(document).ready(
function () {
SelectRow(
" #<%=GridView1.ClientID %> " );
});

< / script>

public partial class TextBoxSelectDialogDefault : PageBase
{
protected string dataKey = string.Empty;
//protected TextBoxSelectXmlModel xmlModel = null;
#region ViewState Property
protected TextBoxSelectXmlModel xmlModel
{
set
{
ViewState[
"xmlModel"] = value;
}
get
{
if (ViewState["xmlModel"] == null)
{
return new TextBoxSelectXmlModel();
}
else
{
return (TextBoxSelectXmlModel)ViewState["xmlModel"];
}
}
}
private int StartHiddenIndex
{
set
{
ViewState[
"StartHiddenIndex"] = value;
}
get
{
if (ViewState["StartHiddenIndex"] == null)
{
return 0;
}
else
{
return (int)ViewState["StartHiddenIndex"];
}
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
dataKey
= Request.QueryString["key"];
if (!IsPostBack)
{
GetXmlData();
SetSearchForm();
SetGridColumn();
InitList(
0);
}
}
#region Get XML Data
private void GetXmlData()
{
if (dataKey != string.Empty)
{
xmlModel
= new XmlAnalyze().GetXmlModel(this, dataKey) as TextBoxSelectXmlModel;
if (xmlModel == null)
{
WriteError(
string.Format("The xml file is null,or the DataKey '{0}' has not finded!", dataKey));
}
}
}
#endregion
#region Set Grid Column And Appearance
private void SetGridColumn()
{
string[] showFieldArray = xmlModel.ShowFields.Split(',');
string[] showFieldHeaderArray = xmlModel.ShowFieldsHeader.Split(',');
string[] fieldWidthArray = xmlModel.FieldWidth.Split(',');
if (showFieldArray.Length != showFieldHeaderArray.Length || showFieldHeaderArray.Length != fieldWidthArray.Length)
WriteError(
"FieldWidth,ShowFields or ShowFieldsHeader's Columns are not equal! ");
string[] hiddenFieldArray = xmlModel.HiddenFields.Split(',');
for (int i = 0; i < showFieldArray.Length; i++)
{
BoundField col
= new BoundField();
col.HeaderText
= showFieldHeaderArray[i];
//col.AccessibleHeaderText = showFieldArray[i];
col.DataField = showFieldArray[i];
col.HeaderStyle.Width
= new Unit(fieldWidthArray[i]);
GridView1.Columns.Add(col);
}
StartHiddenIndex
= showFieldArray.Length;

foreach (string hf in hiddenFieldArray)
{
BoundField colHidden
= new BoundField();
colHidden.DataField
= hf;
GridView1.Columns.Add(colHidden);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.Footer))
{
for (int i = StartHiddenIndex; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Style.Add(HtmlTextWriterStyle.Display,
"none");
}
}
if (e.Row.RowType == DataControlRowType.Header)
{
string[] allFields= string.Format("{0},{1}", xmlModel.ShowFields, xmlModel.HiddenFields).Split(',');

for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].ID
= allFields[i];
e.Row.Cells[i].CssClass
= "TableHeader";
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.CssClass
= "TableItem";
}
}
}
#endregion
#region Set Search Form Appearance
private void SetSearchForm()
{
if (xmlModel.SearchFields == string.Empty)
{
panelSearch.Visible
= false;
return;
}
hiddenParams.Value
= xmlModel.CallBackParams;
lbDescription.Text
= xmlModel.SearchFieldsHeader;

}
#endregion
#region Search Event
protected void btnSearch_Click(object o, EventArgs e)
{
//GetXmlData();
string[] searchFieldsArray = xmlModel.SearchFields.Split(',');
StringBuilder sbWhere
= new StringBuilder();
if (txtKeyWord.Text.Trim() != string.Empty)
{
sbWhere.Append(
" and ");
foreach (string field in searchFieldsArray)
{
sbWhere.Append(
string.Format("{0} like '%{1}%' or ", field, txtKeyWord.Text.Trim()));
}
sbWhere.Remove(sbWhere.Length
- 4, 4);
ViewState[WhereStr]
= sbWhere.ToString();
}
else
{
ViewState[WhereStr]
= null;
}
InitList(
1);
}
#endregion
#region Init List
private void InitList(int currentPage)
{
int recordCount = 0;
DataTable dt
= new DataTable();
StringBuilder sbWhere
= new StringBuilder();
if (ViewState[WhereStr] != null)
{
sbWhere.Append(ViewState[WhereStr].ToString());
}
if (xmlModel.Where != string.Empty)
{
sbWhere.Append(
" and ");
sbWhere.Append(xmlModel.Where);
}
Paged.GetPagedData(xmlModel.TableName,
xmlModel.HiddenFields
!= string.Empty ? string.Format("{0},{1}", xmlModel.ShowFields, xmlModel.HiddenFields) : xmlModel.ShowFields,
PageSize, currentPage,
xmlModel.Order, sbWhere.ToString(),
out recordCount, ref dt);
this.GridView1.DataSource = dt.DefaultView;
this.GridView1.DataBind();
AspNetPager1.CurrentPageIndex
= currentPage;
AspNetPager1.RecordCount
= recordCount;
AspNetPager1.PageSize
= PageSize;
}
#endregion
#region Change Page Index
protected void AspNetPager1_PageChanging(object o, Wuqi.Webdiyer.PageChangingEventArgs e)
{
//GetXmlData();
InitList(e.NewPageIndex);
}
#endregion

public interface IXmlAnalyze
{
object GetXmlModel(Page page, string dataKey);
}
public class XmlAnalyze : IXmlAnalyze
{
public static DataSet XmlDataSet = new DataSet( " XmlDataSet " );
private string filePath = string .Empty;
public XmlAnalyze()
{
filePath
= " /Resources/XML/TextBoxSelect.xml " ;
}
/// <summary>
/// Relative path
/// </summary>
/// <param name="filePath"></param>
public XmlAnalyze( string filePath)
{
this .filePath = filePath;
}
protected void LoadXMLData(Page page)
{
string fileAbsPath = page.Server.MapPath(filePath);
// xmlDoc.Load(fileAbsPath);
XmlDataSet.ReadXml(fileAbsPath,XmlReadMode.ReadSchema);
}
public virtual object GetXmlModel(Page page, string dataKey)
{
if ( ! XmlDataSet.Tables.Contains( " TextBoxSelect " ))
{
LoadXMLData(page);
}
if ( ! XmlDataSet.Tables.Contains( " TextBoxSelect " )) return null ;
foreach (DataRow dr in XmlDataSet.Tables[ " TextBoxSelect " ].Rows)
{
if (dr[ " DataKey " ].ToString().ToLower() == dataKey.ToLower())
{
TextBoxSelectXmlModel model
= new TextBoxSelectXmlModel();
model.DataKey
= dataKey;
model.TableName
= dr[ " TableName " ].ToString();
model.ShowFields
= dr[ " ShowFields " ].ToString();
model.Title
= dr[ " Title " ].ToString();
model.ShowFieldsHeader
= dr[ " ShowFieldsHeader " ].ToString();
model.ValueTextFields
= dr[ " ValueTextFields " ].ToString();
model.FieldWidth
= dr[ " FieldWidth " ].ToString();
model.HiddenFields
= dr[ " HiddenFields " ].ToString();
model.SearchFields
= dr[ " SearchFields " ].ToString();
model.SearchFieldsHeader
= dr[ " SearchFieldsHeader " ].ToString();
model.Where
= dr[ " Where " ].ToString();
model.Order
= dr[ " Order " ].ToString();
model.CallBackParams
= dr[ " CallBackParams " ].ToString();

return model;
}
}
return null ;
}
}
[Serializable]
public class TextBoxSelectXmlModel
{
public string DataKey { get ; set ; }
public string TableName { get ; set ; }
public string Title { get ; set ; }
public string ShowFields { get ; set ; }
public string ShowFieldsHeader { get ; set ; }
public string ValueTextFields { get ; set ; }
public string FieldWidth { get ; set ; }
public string HiddenFields { get ; set ; }
public string SearchFields { get ; set ; }
public string SearchFieldsHeader { get ; set ; }
public string Where { get ; set ; }
public string Order { get ; set ; }
public string CallBackParams { get ; set ; }
}

这是XML文件的分析工具

<?xml version="1.0" encoding="utf-8" ?>
<TextBoxSelectXML>
<xs:schema id="TextBoxSelectXML" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="TextBoxSelectXML" msdata:IsDataSet="true" msdata:Locale="en-US">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="TextBoxSelect">
<xs:complexType>
<xs:sequence>
<xs:element name="DataKey" type="xs:string" minOccurs="0" />
<xs:element name="TableName" type="xs:string" minOccurs="0" />
<xs:element name="Title" type="xs:string" minOccurs="0" />
<xs:element name="ShowFields" type="xs:string" minOccurs="0" />
<xs:element name="ShowFieldsHeader" type="xs:string" minOccurs="0" />
<xs:element name="ValueTextFields" type="xs:string" minOccurs="0" />
<xs:element name="FieldWidth" type="xs:string" minOccurs="0" />
<xs:element name="HiddenFields" type="xs:string" minOccurs="0" />
<xs:element name="SearchFields" type="xs:string" minOccurs="0" />
<xs:element name="SearchFieldsHeader" type="xs:string" minOccurs="0" />
<xs:element name="Where" type="xs:string" minOccurs="0" />
<xs:element name="Order" type="xs:string" minOccurs="0" />
<xs:element name="CallBackParams" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<TextBoxSelect>
<DataKey>UserRole</DataKey>
<TableName>UserRole</TableName><!--必须-->
<Title>角色信息</Title><!--必须-->
<ShowFields>RoleID,RoleName</ShowFields><!--必须-->
<ShowFieldsHeader>角色编号,角色名称</ShowFieldsHeader><!--必须-->
<ValueTextFields>RoleID,RoleName</ValueTextFields><!--必须-->
<FieldWidth>30%,70%</FieldWidth>
<HiddenFields></HiddenFields>
<SearchFields>RoleName</SearchFields>
<SearchFieldsHeader>角色名称</SearchFieldsHeader><!--必须(这不是头,是关键字解释)-->
<Where></Where>
<Order>RoleID desc</Order><!--必须-->
<CallBackParams></CallBackParams><!--这是需要回CallBackFunction时的参数-->
</TextBoxSelect>
</TextBoxSelectXML>\


* *****************表行变色************************ */
function ShowRowColor(id) {
var tbl = $(id)[ 0 ];
if (tbl) {
for ( var i = 1 ; i < tbl.rows.length; i ++ ) {
tbl.rows[i].onmouseover
= function () {
for ( var j = 0 ; j < this .cells.length; j ++ ) {
this .cells[j].style.backgroundColor = " #EDF1E8 " ;
}
}
tbl.rows[i].onmouseout
= function () {
for ( var j = 0 ; j < this .cells.length; j ++ ) {
this .cells[j].style.backgroundColor = " #FFFFFF " ;
}
}
}
}
}
/* *****************表行变色************************ */

这个是行变色,是在弹出框页面中调用

/// <summary>
/// 获取分页数据
/// </summary>
/// <param name="tableName"></param>
/// <param name="colName"></param>
/// <param name="pageSize"></param>
/// <param name="currentPage"></param>
/// <param name="orderStr"></param>
/// <param name="whereStr"></param>
/// <param name="recordCount"></param>
/// <param name="returnDT"></param>
public static void GetPagedData( string tableName, string colName, int pageSize, int currentPage,
string orderStr, string whereStr, out int recordCount, ref DataTable returnDT)
{
SqlParameter paramCount
= new SqlParameter( " @recordCount " , SqlDbType.Int);
paramCount.Direction
= ParameterDirection.Output;
SqlParameter[] paramArray
= {
new SqlParameter( " @tableName " , tableName),
new SqlParameter( " @colName " , colName),
new SqlParameter( " @pageSize " , pageSize),
new SqlParameter( " @currentPage " , currentPage),
new SqlParameter( " @orderStr " , orderStr),
new SqlParameter( " @whereStr " , whereStr),
paramCount
};
returnDT
= DbHelper.DbHelperSQL.RunProcedureForList( " usp_pagination " , paramArray);
recordCount
= int .Parse(paramCount.Value.ToString());
}
public static void GetPagedData( string tableName, int currentPage,
string orderStr, out int recordCount, ref DataTable returnDT)
{
int pageSize = 10 ;
string whereStr = string .Empty;
string colName = " * " ;
GetPagedData(tableName, colName, pageSize, currentPage,
orderStr, whereStr,
out recordCount, ref returnDT);
}

这是弹出框显示列表数据时调用的分页代码\

t ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go




-- =============================================
--
Author: <Anncesky>
--
Create date: <2008/3/16>
--
Description: <Paged>
--
=============================================
ALTER PROCEDURE [ dbo ] . [ usp_pagination ]
@tableName varchar ( 255 ), -- 表名
@colName varchar ( 255 ) = ' * ' , -- 字段名串
@pageSize int = 10 , -- 页尺寸
@currentPage int = 1 , -- 页码
@orderStr varchar ( 255 ) = '' , -- 排序类型字段串(不带order by,带asc,desc,必须的)
@whereStr varchar ( 255 ) = '' , -- 查询条件 (注意: 不要加 where)
@recordCount int output
AS
BEGIN
SET NOCOUNT ON ;
declare @sql nvarchar ( 4000 )
declare @TotalPages int

-- 计算总记录数及总页数
set @sql = ' select @recordCount = count(*) from ' + @tableName + ' where 1=1 ' + @whereStr
exec sp_executesql @sql ,N ' @recordCount int output ' , @recordCount output
select @TotalPages = CEILING (( @recordCount + 0.0 ) / @PageSize )

-- 处理页数超出范围情况
if @currentPage <= 0
set @currentPage = 1
if @currentPage > @TotalPages
set @currentPage = @TotalPages
set @sql = ' select ' + @colName + ' from (select top(@currentPage*@pageSize) ' + @colName + ' ,row_number() over(order by ' + @orderStr + ' ) as rowNumber from ' + @tableName + ' where 1=1 ' + @whereStr + ' ) t where t.rowNumber >= ((@currentPage-1)*@pageSize+1) '

-- print @Sql
exec sp_executesql @sql ,N ' @currentPage int, @pageSize int ' , @currentPage , @pageSize
END

分页存储过程


转载于:https://www.cnblogs.com/shenzhenjia/archive/2011/08/02/2125509.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值