当前位置: 代码迷 >> ASP.NET >> 有志者求gridview有关问题解答
  详细解决方案

有志者求gridview有关问题解答

热度:407   发布时间:2013-02-26 00:00:00.0
有志者求gridview问题解答
<%@   Page   Language= "C# "   AutoEventWireup= "true "   CodeFile= "pagechanging.aspx.cs "   Inherits= "pagechanging "   %>

<!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> Untitled   Page </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
        <table>
        <tr>
        <td>
        <asp:Button   ID= "bt1 "   runat=server   Text= "查询 "   OnClick= "bt1_Click "   />
        </td>
        </tr>
        <tr>
        <td>
        <asp:GridView   ID= "gridview1 "   AllowPaging=true   runat=server   AutoGenerateColumns=false   OnPageIndexChanging= "gridview1_PageIndexChanging "   PageSize= "5 ">
        <Columns>
        <asp:BoundField   HeaderText= "名称 "   DataField= "job_desc "   />
        <asp:BoundField   HeaderText= "最小数 "   DataField= "min_lvl "   />
        <asp:BoundField   HeaderText= "最大数 "   DataField= "max_lvl "   />
        </Columns>
        </asp:GridView>
        </td>
        </tr>
        </table>
        </div>
        </form>
</body>
</html>


.cs
using   System;
using   System.Data;
using   System.Configuration;
using   System.Collections;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;
using   System.Data.SqlClient;  

public   partial   class   pagechanging   :   System.Web.UI.Page
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                if   (!IsPostBack)
                {
                        gridview1.DataBind();
                }
               
        }
        protected   void   bt1_Click(object   sender,   EventArgs   e)
        {
                SqlConnection   con   =   DB.createConnection();