打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
易动分页

前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td width="100%">
                    <asp:GridView ID="GridViewItems" runat="server" AutoGenerateColumns="False" border="0"
                        CellPadding="0" ShowFooter="True" UseAccessibleHeader="False" GridLines="None"
                        ForeColor="#333333" PageSize="1000"
                        onrowdatabound="GridViewItems_RowDataBound">
                        <Columns>
                            <asp:TemplateField HeaderText="閫夋嫨" FooterText="閫夋嫨">
                                <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <input type="checkbox" name="checkme" value='<%# Eval("Id")%>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="ID" FooterText="Id">
                                <ItemTemplate>
                                    <%# Eval("Id")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="鍚嶇О" FooterText="鍚嶇О">
                                <ItemTemplate>
                                    <%# Eval("Titles")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="鍒嗙被" FooterText="鍒嗙被">
                                <ItemTemplate>
                                    <%# Eval("CategoryName")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="鍏呰璇勮" FooterText="鍏呰璇勮">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnAllowComment" runat="server" CommandName="Comment" CommandArgument='<%# Eval("Id") %>'></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="鎺ㄨ崘" FooterText="鎺ㄨ崘">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnCommend" runat="server" CommandName="Commend" CommandArgument='<%# Eval("Id") %>'></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="鏄剧ず" FooterText="鏄剧ず">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnState" runat="server" CommandName="State" CommandArgument='<%# Eval("Id") %>'></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="璁块棶鏁? FooterText="璁块棶鏁?>
                                <ItemTemplate>
                                    <%# Eval("Visits")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="璇勮鏁? FooterText="璇勮鏁?>
                                <ItemTemplate>
                                    <%# Eval("Comments")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="椤惰创鏁? FooterText="椤惰创鏁?>
                                <ItemTemplate>
                                    <%# Eval("Support")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="鏂囦欢鍚? FooterText="鏂囦欢鍚?>
                                <ItemTemplate>
                                    <%# Eval("FileName")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="鎿嶄綔" FooterText="鎿嶄綔">
                                <ItemTemplate>
                                    <a href="?action=edit&i=<%# Eval("id") %>">淇敼</a><asp:LinkButton ID="btnDel" runat="server"
                                        CommandName="Del" CommandArgument='<%# Eval("id") %>'> <span onclick="return confirm('纭畾鍒犻櫎璇ヤ俊鎭悧锛焅n\n鍒犻櫎鍚庢棤娉曟仮澶嶏紒');">鍒犻櫎</span></asp:LinkButton>
                                    <asp:HiddenField ID="HiPicture" runat="server" Value='<%# Eval("Pictures")%> ' />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#F6F6F6" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td width="100%">
                    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
                        <tr bgcolor="#E7E7E7">
                            <td align="center" bgcolor="#E7E7E7" style="width: 900px; color: #000000">
                                <asp:Label ID="Label1" CssClass="font1" runat="server" Text="Label"></asp:Label>
                                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                                 
                                <asp:HyperLink ID="start" runat="server" ForeColor="#000000">棣栥€€椤?/asp:HyperLink>
                                 
                                <asp:HyperLink ID="prev" runat="server" ForeColor="#000000"> 涓婁竴椤?/asp:HyperLink>
                                 
                                <asp:HyperLink ID="next" runat="server" ForeColor="#000000">涓嬩竴椤?/asp:HyperLink>
                                 
                                <asp:HyperLink ID="max" runat="server" ForeColor="#000000">鏈€€椤?/asp:HyperLink>
                                <span class="font1">杞悜</span>
                                <asp:DropDownList ID="iPage" runat="server" AutoPostBack="True"  OnSelectedIndexChanged="sic">
                                </asp:DropDownList>
                                <input id="chkall" type="checkbox" onclick="CheckAll(this.form)" style="border: 0" />鍏ㄩ€?
                            </td>
                            <td align="left" style="width: 50px">
                            </td>
                            <td align="left" bgcolor="#E7E7E7" style="width: 180px">
                            </td>
                            <td align="center" style="width: 50px">
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
 
 
后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            GVBind();
        }
    }
    public void GVBind()
    {
        SqlParameter p=null;
        DataSet ds = SqlHelper.ExecuteDataSet(System.Data.CommandType.Text, "select * from D_Information", p);
        GridViewItems.DataSource = datalistbind(ds);
        GridViewItems.DataBind();
    }
    private PagedDataSource datalistbind(DataSet dst)
    {
        PagedDataSource objpage = new PagedDataSource();
        objpage.DataSource = dst.Tables[0].DefaultView;
        objpage.AllowPaging = true;
        //dg1.PageSize = 20;
        objpage.PageSize = 20;
        int CurPage;
        //判断是否有分??
        ///
        if (Request["iPage"] != null)
        {
            CurPage = Convert.ToInt32(Request["iPage"]);
        }
        else
        {
            CurPage = 1;
        }
        //?当前?
        objpage.CurrentPageIndex = CurPage - 1;
        Label1.Text = "当前?第 + CurPage.ToString() + "/" + objpage.PageCount + ";
        Label2.Text = "共有 + objpage.DataSourceCount + "条?  + objpage.PageSize + "/;
        //判断不是第一?时候
        if (!objpage.IsFirstPage)
        {
            this.prev.NavigateUrl = Request.CurrentExecutionFilePath + "?iPage=" + (Convert.ToInt32(CurPage) - 1) + "&Flag=" + Request["Flag"];
        }
        this.start.NavigateUrl = Request.CurrentExecutionFilePath + "?iPage=1" + "&Flag=" + Request["Flag"];
        //判断不是最后一?时候
        if (!objpage.IsLastPage)
        {
            this.next.NavigateUrl = Request.CurrentExecutionFilePath + "?ipage=" + (Convert.ToInt32(CurPage) + 1) + "&Flag=" + Request["Flag"];
        }
        this.max.NavigateUrl = Request.CurrentExecutionFilePath + "?iPage=" + objpage.PageCount + "&Flag=" + Request["Flag"];
        if (!IsPostBack)
        {
            for (int i = 1; i < objpage.PageCount + 1; i++)
            {
                this.iPage.Items.Add(new ListItem(i.ToString() + ", i.ToString()));
            }
        }
        return objpage;
    }
    protected void sic(object sender, EventArgs e)
    {
        SqlParameter p = null;
        DataSet ds = SqlHelper.ExecuteDataSet(System.Data.CommandType.Text, "select * from D_Information", p);
        PagedDataSource objpage = new PagedDataSource();
        objpage.DataSource = ds.Tables[0].DefaultView;
        objpage.AllowPaging = true;
        //dg1.PageSize = 20;
        objpage.PageSize = 20;
        int CurPage;
        //判断是否有分??        ///
        if (iPage.SelectedValue != null)
        {
            CurPage = Convert.ToInt32(iPage.SelectedValue);
        }
        else
        {
            CurPage = 1;
        }
        //?当前?
        objpage.CurrentPageIndex = CurPage - 1;
        Label1.Text = "当前?第 + CurPage.ToString() + "/" + objpage.PageCount + ";
        Label2.Text = "共有 + objpage.DataSourceCount + "条?  + objpage.PageSize + "/;
        //判断不是第一?时候
        if (!objpage.IsFirstPage)
        {
            this.prev.NavigateUrl = Request.CurrentExecutionFilePath + "?iPage=" + (Convert.ToInt32(CurPage) - 1) + "&Flag=" + Request["Flag"];
        }
        this.start.NavigateUrl = Request.CurrentExecutionFilePath + "?iPage=1" + "&Flag=" + Request["Flag"];
        //判断不是最后一?时候
        if (!objpage.IsLastPage)
        {
            this.next.NavigateUrl = Request.CurrentExecutionFilePath + "?ipage=" + (Convert.ToInt32(CurPage) + 1) + "&Flag=" + Request["Flag"];
        }
        this.max.NavigateUrl = Request.CurrentExecutionFilePath + "?iPage=" + objpage.PageCount + "&Flag=" + Request["Flag"];
        if (!IsPostBack)
        {
            for (int i = 1; i < objpage.PageCount + 1; i++)
            {
                this.iPage.Items.Add(new ListItem(i.ToString() + ", i.ToString()));
            }
        }
        this.GridViewItems.DataSource = objpage; //ds.Tables["dstable"].DefaultView;
        this.GridViewItems.DataBind();
    }
    protected void GridViewItems_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex == -1) return;
        e.Row.Attributes.Add("bgcolor", "#EFFFDA");
        e.Row.Attributes.Add("style", "cursor:hand");
        e.Row.Attributes.Add("onMouseOver=this.style.backgroundColor", "#EDEBEF");
        e.Row.Attributes.Add("onMouseOut=this.style.backgroundColor", "#F6F6F6");
    }
}
sqlhelp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public abstract class SqlHelper
{
    public static readonly string connectionString = ConfigurationManager.ConnectionStrings["Devin:SqlServer"].ConnectionString;
    private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
    protected SqlHelper()
    {
    }
    public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters)
    {
        parmCache[cacheKey] = commandParameters;
    }
    public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        return ExecuteDataSet(cmdType, cmdText, "DefaultTable", commandParameters);
    }
    public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string TableName, params SqlParameter[] commandParameters)
    {
        DataSet set2;
        SqlCommand cmd = new SqlCommand();
        SqlConnection conn = new SqlConnection(connectionString);
        try
        {
            PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, TableName);
            adapter.Dispose();
            cmd.Dispose();
            conn.Close();
            set2 = dataSet;
        }
        catch
        {
            throw;
        }
        return set2;
    }
    public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        SqlCommand cmd = new SqlCommand();
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            int num = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            cmd.Dispose();
            connection.Close();
            return num;
        }
    }
    public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        SqlCommand cmd = new SqlCommand();
        PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
        int num = cmd.ExecuteNonQuery();
        cmd.Parameters.Clear();
        cmd.Dispose();
        return num;
    }
    public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        SqlCommand cmd = new SqlCommand();
        PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
        int num = cmd.ExecuteNonQuery();
        cmd.Parameters.Clear();
        cmd.Dispose();
        return num;
    }
    public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        SqlDataReader reader2;
        SqlCommand cmd = new SqlCommand();
        SqlConnection conn = new SqlConnection(connectionString);
        try
        {
            PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            cmd.Parameters.Clear();
            reader2 = reader;
        }
        catch
        {
            conn.Close();
            throw;
        }
        return reader2;
    }
    public static object ExecuteScalar(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        SqlCommand cmd = new SqlCommand();
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            object obj2 = cmd.ExecuteScalar();
            cmd.Parameters.Clear();
            return obj2;
        }
    }
    public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
    {
        SqlCommand cmd = new SqlCommand();
        PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
        object obj2 = cmd.ExecuteScalar();
        cmd.Parameters.Clear();
        return obj2;
    }
    public static SqlParameter[] GetCachedParameters(string cacheKey)
    {
        SqlParameter[] parameterArray = (SqlParameter[])parmCache[cacheKey];
        if (parameterArray == null)
        {
            return null;
        }
        SqlParameter[] parameterArray2 = new SqlParameter[parameterArray.Length];
        int index = 0;
        int length = parameterArray.Length;
        while (index < length)
        {
            parameterArray2[index] = (SqlParameter)((ICloneable)parameterArray[index]).Clone();
            index++;
        }
        return parameterArray2;
    }
    private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
    {
        if (conn.State != ConnectionState.Open)
        {
            conn.Open();
        }
        cmd.Connection = conn;
        cmd.CommandText = cmdText;
        if (trans != null)
        {
            cmd.Transaction = trans;
        }
        cmd.CommandType = cmdType;
        if (cmdParms != null)
        {
            foreach (SqlParameter parameter in cmdParms)
            {
                if (parameter != null && !string.IsNullOrEmpty((parameter.Value as string)) || (parameter.Value is int))
                {
                    cmd.Parameters.Add(parameter);
                }
            }
        }
    }
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
微软提供的数据访问组件SqlHelper
存储过程
步步为营 .NET三层架构解析 三、SQLHelper设计-程序开发-红黑联盟
一个操作Sql2005数据库的类(备份,还原,分离,附加,添加删除用户等操作)
EXT2.2+C#.net+Sql 2005实现将数据导入Excel保存
浅谈PetShop之使用存储过程与PLSQL批量处理(附案例)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服