asp.net--slider控件

.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="slider_综合实例.aspx.cs" Inherits="lesson_code_Default2" %>


<!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>
    <style type ="text/css">
        #div_nav{ width:200px;}
        #div_content { width:500px; 
                       margin-left:20px;
                       padding:10px; }
        
        .myHandle { width:10px; height:10px;
                    margin-top:10px; }
        .myRail { width:500px; height:10px;
                  background-image:url("../img/rail_pm.png"); background-repeat:no-repeat;
                  position:relative;   }
    </style>
    <link href="../CSS/CSS_DEFAULT.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="div_nav" class ="fl">
            <asp:TreeView ID="tv_date" runat="server" 
                onselectednodechanged="tv_date_SelectedNodeChanged" ShowCheckBoxes="All">
            </asp:TreeView> 


            <asp:Button ID="btn_showList" runat="server" Text="Button" 
                onclick="btn_showList_Click" />
        </div>


        <myatk:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </myatk:ToolkitScriptManager>



        <div id="div_content" class ="fl">
            
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


                    <asp:ListView ID="ListView1" runat="server" DataSourceID="AccessDataSource1"
             ItemPlaceholderID="itemHolder">
                <LayoutTemplate>
                    <div id="itemHolder" runat="server"></div>
                </LayoutTemplate>


                <ItemTemplate>
                    <h3> <%#Eval("pm_date","{0:D}") %></h3>
                    <asp:TextBox ID="txt_pm25" runat="server" 
                        Text=‘<%#Eval("pm_val") %>‘/>


                    <myatk:SliderExtender ID="TextBox1_SliderExtender" runat="server" 
                        Enabled="True" Maximum="500" Minimum="0" TargetControlID="txt_pm25" 
                        HandleCssClass="myHandle" HandleImageUrl="~/IMG/handle_pm.png" 
                        RailCssClass="myRail">
                    </myatk:SliderExtender>


                </ItemTemplate>


            </asp:ListView>
            <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                DataFile="~/DATA/pm25.mdb" 
                SelectCommand="SELECT * FROM [T_PM25] WHERE ([pm_id] = ?)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="tv_date" DefaultValue="1" Name="pm_id" 
                        PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
            </asp:AccessDataSource>


                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID ="btn_showList" />
                </Triggers>


            </asp:UpdatePanel>
            
            
        </div>


        <div class ="clr"></div>


    </div>
    </form>
</body>
</html>

.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

public partial class lesson_code_Default2 : System.Web.UI.Page
{    string str_cnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
    string str_sourcefile = "~/data/pm25.mdb";
    OleDbConnection cnn;
    OleDbCommand cmd;
    OleDbDataReader datar;
    string str_sql;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            maketree();
        }
    }

    protected void maketree() { 
        string str_conn = str_cnn + MapPath(str_sourcefile);
        cnn = new OleDbConnection(str_conn);
        cnn.Open();

        str_sql = "SELECT * FROM T_PM25";

        cmd = new OleDbCommand(str_sql, cnn);
        datar = cmd.ExecuteReader();

        TreeNode _tnode;
        while (datar.Read()) {
            _tnode = new TreeNode();
            _tnode.Text = string.Format("{0:D}", (DateTime)datar["pm_date"]);
            _tnode.Value = datar["pm_id"].ToString();
            //_tnode.Value = datar["pm_val"].ToString();
            tv_date.Nodes.Add(_tnode);
        }

        cnn.Close();
    }
    protected void tv_date_SelectedNodeChanged(object sender, EventArgs e)
    {
        //TextBox1.Text = tv_date.SelectedValue;
    }
    protected void btn_showList_Click(object sender, EventArgs e)
    {
        string _values = "";
        foreach (TreeNode _tnode in tv_date.CheckedNodes) {//遍历整个树
            _values += _tnode.Value + ",";//用于拼写SQL语句
        }

        string _sql = "SELECT * FROM T_PM25 WHERE PM_ID IN ("+_values+")";
        //TextBox1.Text = _sql;
        AccessDataSource1.SelectCommand = _sql;//设定数据源的控制语句
        
    }
}

效果如下:


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。