通用弹出页面,双击行选择设计

aspx: 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="olePage.aspx.cs" Inherits="Process_BasicDataPopup_olePage" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <link href="http://www.cnblogs.com/CSS/admin.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function MouseEvent(ctl) {
            var pColor = ctl.style.backgroundColor
            if (pColor != "white") {
                ctl.style.backgroundColor = "white";
            }
            else {
                ctl.style.backgroundColor = "#EDEDED";
            }
        }
        function PageReturn(value,text)
        {
                top.workFlowStatusWindow[2] = value;//选择的计费人
                top.workFlowStatusWindow[3] = text;//要填充的文本框
                top.workFlowStatusWindow[0].close();
          
        }
    </script>

</head>
<body topmargin="0" leftmargin="0" style="text-align: left" class="">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:TextBox ID="txtSearch" runat="server" Width="77%" BorderStyle="Solid" BorderWidth="1px"></asp:TextBox>
    <asp:Button ID="btnSearch" runat="server" Width="20%" Text="搜索" class="btnCommon"  Height="20"/>
    <asp:DataGrid ID="dgResult" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        BackColor="White" BorderColor="#EEEFF" BorderStyle="None" CellPadding="0" CssClass="table"
        PageSize="80" ToolTip="双击行直接选择!" Width="100%" AllowSorting="True">
        <FooterStyle BackColor="#dfe8f7" ForeColor="Red" HorizontalAlign="Right" VerticalAlign="Middle"
            Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
            Font-Underline="False" />
        <SelectedItemStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        <ItemStyle BackColor="White" CssClass="TableItem" ForeColor="Black" VerticalAlign="Middle"
            Width="100px" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
            Font-Underline="False" Font-Names="宋体" Font-Size="Smaller" />
        <HeaderStyle BackColor="#dfe8f7" CssClass="TableHead" Font-Bold="True" Font-Size="Smaller"
            Height="21px" HorizontalAlign="Center" Font-Italic="False" Font-Overline="False"
            Font-Strikeout="False" Font-Underline="False" />
        <PagerStyle BackColor="White" ForeColor="Red" HorizontalAlign="Left" NextPageText="Pre."
            PageButtonCount="30" PrevPageText="Next" Font-Bold="False" Font-Italic="False"
            Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Visible="False" />
    </asp:DataGrid>
    <asp:Label ID="lblSQL" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="lblName" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="lblWidth" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="lblConn" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="lblOrder" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="lblTitle" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="lblPlan" runat="server" Text="Label" Visible="False"></asp:Label>
    <asp:Label ID="lblText" runat="server" Text="Label" Visible="False"></asp:Label>
   
    </form>
</body>
</html>

CS:

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Data;
using Macrowing.Comm.Dal;
using Macrowing.Comm.Common;
using Macrowing.Comm.Log;
using System.Text;

public partial class Process_BasicDataPopup_olePage : System.Web.UI.Page
{
    #region 变量声明
    string strSQL;
    string strName;
    string strWidth;
    string strConn;
    string strOrder;
    string strSQLOrder;
    string strTitle;
    string strPlan = string.Empty;
    string strText = string.Empty;
    DataTable dtQuery = new DataTable();
    DataTable dtTotal = new DataTable();
    BaseDal oleDB = new BaseDal();
    clsOleDB clsDB = new clsOleDB();
    SystemLogger wrLog = new SystemLogger();
    #endregion


    #region 事件定义
    protected void Page_Load(object sender, System.EventArgs e)
    {
        #region 取得传入的参数
        //取得传入的参数
        if (!Page.IsPostBack)
        {
            strSQL = Request.QueryString.Get("SQL");
            strName = Request.QueryString.Get("Name");
            strWidth = Request.QueryString.Get("Width");
            strConn = Request.QueryString.Get("Conn");
            strOrder = Request.QueryString.Get("Order");
            strTitle = Request.QueryString.Get("Title");
            strPlan = Request.QueryString.Get("Plan");
            strText = Request.QueryString.Get("Text");
            lblSQL.Text = strSQL;
            lblName.Text = strName;
            lblWidth.Text = strWidth;
            lblConn.Text = strConn;
            lblOrder.Text = strOrder;
            lblTitle.Text = strTitle;
            lblPlan.Text = strPlan;
            lblText.Text = strText;
        }
        else
        {
            strSQL = lblSQL.Text;
            strName = lblName.Text;
            strWidth = lblWidth.Text;
            strConn = lblConn.Text;
            strOrder = lblOrder.Text;
            strTitle = lblTitle.Text;
        }
        #endregion

        #region 测试数据
        //strSQL = "1001#NewProcess~12";
        //strName = "stepname~userfullname~name~signdate~remarks";
        //strWidth = "100~100~100~100~100";
        //strConn = "oleDB";
        //strOrder = "remarks";
        #endregion

        #region 数据合法性验证
        if (strName == null)
        {
            strName = "";
        }

        if (strWidth == null)
        {
            strWidth = "";
        }

        if (strConn == null || strConn == "")
        {
            strConn = "bpmDB";
        }
        #endregion

        //从配置文件中取得对应的 SQL, 并进行格式化
        string strMainSql = clsDB.getConn2(strSQL.Split('$')[0]);
        string[] strSqlPara = strSQL.Split('$')[1].Split('~');

        //将参数对应的值对号入座
        for (int i = 0; i < strSqlPara.Length; i++)
        {
            strMainSql = strMainSql.Replace("{" + i.ToString() + "}", strSqlPara[i]);
        }

        if (!Page.IsPostBack)
        {
            //clsDB.setConn(strConn);
            //wrLog.WriterLog(@"C:\logZaiq.txt", "调用olePage4方法SQL:" + strMainSql);
            dtQuery = oleDB.SelectCommand(strMainSql, null);

            //初始化DataGrid列
            InitGrid(dgResult, dtQuery, strName, strWidth);
            if (dtQuery != null)
            {
                BindGrid(dgResult, dtQuery);
            }
        }
        else
        {
            if (strOrder != null && strOrder != "")
            {
                strSQLOrder = "select * from (" + strMainSql + ") T_Tmps where " + strOrder + " like '%" + this.txtSearch.Text.Replace("'", "").Trim().ToString() + "%'";
            }
            else
            {
                strSQLOrder = strMainSql;
            }

            //clsDB.setConn(strConn);
            //wrLog.WriterLog(@"C:\logZaiq.txt", "调用olePage4方法SQLOrder:" + strSQLOrder);
            dtQuery = oleDB.SelectCommand(strSQLOrder, null);

            //初始化DataGrid列
            InitGrid(dgResult, dtQuery, strName, strWidth);
            if (dtQuery != null)
            {
                BindGrid(dgResult, dtQuery);
            }
        }

        Response.Buffer = true;
        Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        Response.Write("<script language=javascript>document.title=\"" + strTitle + "\"</script>");
    }

    #endregion

    #region 方法定义
    /// <summary>
    /// 初始化DataGrid列
    /// </summary>
    private void InitGrid(DataGrid dg, DataTable dt, string strName, string strWidth)
    {
        //列名
        string[] strArrName = strName.Split('~');
        string[] strArrWidth = strWidth.Split('~');

        //清空DataGrid
        dg.Columns.Clear();

        //根据查询得到的Dataset进行DataGrid列初始化
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            BoundColumn col = new BoundColumn();
            col.DataField = dt.Columns[i].Caption.ToString();
            //列名
            if (i < strArrName.Length && strArrWidth[i].ToString() != "")
            {
                col.HeaderText = strArrName[i];
            }
            else
            {
                col.HeaderText = dt.Columns[i].Caption.ToString() + "";
            }

            //列宽
            if (i < strArrWidth.Length && strArrWidth[i].ToString() != "")
            {
                col.HeaderStyle.Width = Int32.Parse(strArrWidth[i].ToString());
                if (col.HeaderStyle.Width == 0)
                {
                    col.Visible = false;
                }
            }
            else
            {
                col.HeaderStyle.Width = 50;
            }

            dg.Columns.Add(col);
        }
    }

    /// <summary>
    /// 数据邦定
    /// </summary>
    /// <param name="dsData"></param>
    private void BindGrid(DataGrid dg, DataTable dt)
    {
        //将DataGrid与DataSet进行绑定
        if (dt != null)
        {
            dg.DataSource = dt.DefaultView;
            dg.DataBind();
            //为DataGride增加事件方法
            EditGrid(dg);
        }
    }


    /// <summary>
    /// 更新Grid上的字段列
    /// </summary>
    private void EditGrid(DataGrid dg)
    {
        foreach (DataGridItem dgItm in dg.Items)
        {
            //对每行的值进行组合
            string strReturn = "";
            for (int i = 0; i < dg.Columns.Count; i++)
            {
                strReturn += dgItm.Cells[i].Text.Replace("'", "").Replace("\"", "").Replace("\r", "").Replace("\n", "").Replace("\t", "").Trim() + "~";

                //sb.Append("{Key:" + strTxt[i].ToString() + ",Value:" + strReturn + "},");
            }

            dgItm.Attributes.Add("ondblclick", "if(typeof(top.JueKit) == 'undefined') javascript:parent." + lblPlan.Text.ToString() + "('" + strReturn + "','" + lblText.Text.ToString() + "'); else javascript:PageReturn('" + strReturn + "','" + lblText.Text.ToString() + "');");
            //dgItm.Attributes.Add("ondblclick", "PageReturn(" + lblPlan.Text.ToString() + ',' + strReturn + "','" + lblText.Text.ToString() + "');");
            dgItm.Attributes.Add("onfocusout", "javascript:MouseEvent(this);");
            dgItm.Attributes.Add("onfocusin", "javascript:MouseEvent(this);");

        }

    }
    #endregion

    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {

    }

}
    #endregion

 

转载于:https://www.cnblogs.com/tonysun/archive/2010/06/22/1762536.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值