当前位置:编程学习 > C#/ASP.NET >>

网站代码示例:GridView使用示例

网站代码示例:GridView使用示例 --------------------编程问答-------------------- <%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilesControl.ascx.cs" Inherits="UserControl_FilesControl" %>
<link href="../CSS/StyleSheet.css" rel="stylesheet" type="text/css" />
<table width="640px" cellpadding="0" border="0px" cellspacing="0" >
    <tr>
        <td style="border-style:none;">
            <asp:GridView ID="FilesInfoGV" runat="server" Width="100%" AllowPaging="True" AutoGenerateColumns="False" ShowHeader="False" OnPageIndexChanging="FilesInfoGV_PageIndexChanging" OnRowDataBound="FilesInfoGV_RowDataBound" BorderStyle="None" BorderWidth="0px" PageSize="20">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <table border="0" cellpadding="0" cellspacing="0"  class="gundong">
                         <tr>
                            <td width="20" style=" height:25px;" align="center">
                             <asp:Image ID="Image1" runat="server" ImageUrl="../images/dian.JPG"/></td>
                            <td width="540" align="left"><asp:HyperLink  ID="TitleHK" runat="server" Text='<%#Eval("title") %>' NavigateUrl='<%#Eval("id","../Detail.aspx?id={0}" )%>' Target="_blank"></asp:HyperLink></td>
                             <td width="80px" align="center"><asp:Label ID="Label1"  runat="server" Text='<%#Eval("time","{0:yyyy-MM-dd}") %>'></asp:Label></td>
                         </tr>
                         </table>
                    
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
                <PagerSettings FirstPageText="首页" LastPageText="尾页"
                    NextPageText="下一页" PreviousPageText="上一页" Mode="NumericFirstLast" PageButtonCount="14" />
            </asp:GridView>
        </td>
    </tr>
</table>

--------------------编程问答-------------------- 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 DB;

public partial class UserControl_FilesControl : System.Web.UI.UserControl
{
    private DataAccess da = new DataAccess();
    private DataSet ds = new DataSet();

    private int list_id;

    public int List_id
    {
        get { return list_id; }
        set { list_id = value; }
    }
   
    protected void Page_Load(object sender, EventArgs e)
    {
        GetSource();
    }

    protected void GetSource()
    {
        ds = da.GetDs("select title,id,time,ordertime from content where list_id=" + list_id + "  order by ordertime desc");

        FilesInfoGV.DataSource = ds;
        ViewState["sourse"] = ds;
        FilesInfoGV.DataBind();
    }

    protected void FilesInfoGV_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink temp = e.Row.FindControl("TitleHK") as HyperLink;
            if (temp != null)
            {
                temp.Text = temp.Text.Length > 44? temp.Text.Substring(0, 43) + "..." : temp.Text;
            }

        }
    }

    protected void FilesInfoGV_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        FilesInfoGV.PageIndex = e.NewPageIndex;
        GetSource();
      
    }
}
--------------------编程问答-------------------- <%@ Page Language="C#" MasterPageFile="~/View.master" AutoEventWireup="true" CodeFile="File.aspx.cs" Inherits="File" Title="==欢迎访问苏州大学110周年校庆网站==" %>

<%@ Register Src="UserControl/People.ascx" TagName="People" TagPrefix="uc4" %>

<%@ Register Src="UserControl/donateList.ascx" TagName="donateList" TagPrefix="uc3" %>

<%@ Register Src="LeavewordS.ascx" TagName="LeavewordS" TagPrefix="uc2" %>

<%@ Register Src="UserControl/FilesControl.ascx" TagName="FilesControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<!----------------------------右---------------------------->
<br />
<table width="640" border="0" cellspacing="0" cellpadding="0" style="margin-left:-20px;">
         <tr>
            <td align="center" style="height: 40px">
             <asp:Label ID="TitleLB" runat="server" CssClass="BlueTitle"></asp:Label>
             <hr  style=" border:0px; color:#c5010f; height:1px; width:100%"/>
            </td>
         </tr>
         
  <tr>
            <td align="center">
               
                <br />
               
            <asp:Panel ID="InfoPanel" runat="server">
            <div style="text-align:left; width:640px;">
                   <asp:Label ID="DepLB" runat="server" CssClass="MyContent" ></asp:Label>
            </div>
                
            </asp:Panel>
            <br />
            </td>
          </tr>
        </table>
            
        
</asp:Content>

------------------------------------------------------------------------------
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 DB;

public partial class File : System.Web.UI.Page
{
    private DataTable dt = new DataTable();
    private DataAccess da = new DataAccess();
    private static int list_id;

    protected void Page_Load(object sender, EventArgs e)
    {
        list_id = Request.QueryString["list_id"] == null ? 0 : int.Parse(Request.QueryString["list_id"].ToString());
        GetRightInfo();
    }

    //右内容模块
    protected void GetRightInfo()
    {
        if (list_id == 72 || list_id == 73)
        {
            TitleLB.Text = "校友捐赠";
            UserControl_donateList dn = (UserControl_donateList)Page.LoadControl("UserControl/donateList.ascx");
            dn.ID = "72";
            
            InfoPanel.Controls.Add(dn);

            
        }
        else
        {
                    string str = "select * from list where list_id=" + list_id;
                    dt = da.GetTable(str);

                    if (dt.Rows.Count > 0)
                    {
                        
                            string title = dt.Rows[0]["listname"].ToString();
                            TitleLB.Text = title;

                            int type = int.Parse(dt.Rows[0]["type"].ToString());

                            switch (type)
                            {
                                case 0:
                                    break;
                                case 1:
                                    //单条信息
                                    GetDetail();
                                    break;
                                case 2:
                                    //记录集
                                    UserControl_FilesControl fc = (UserControl_FilesControl)Page.LoadControl("UserControl/FilesControl.ascx");
                                    fc.ID = dt.Rows[0]["list_id"].ToString();
                                    fc.List_id = int.Parse(dt.Rows[0]["list_id"].ToString());
                                    InfoPanel.Controls.Add(fc);
                                    break;
                                case 3:
                                    //留言版
                                    LeavewordS lvs = (LeavewordS)Page.LoadControl("LeavewordS.ascx");
                                    lvs.ID = "lvs";
                                    InfoPanel.Controls.Add(lvs);
                                    break;
                                case 4:
                                    //图片集
                                    UserControl_People pc = (UserControl_People)Page.LoadControl("UserControl/People.ascx");
                                    pc.ID = dt.Rows[0]["list_id"].ToString();
                                    pc.List_id = int.Parse(dt.Rows[0]["list_id"].ToString());
                                    InfoPanel.Controls.Add(pc);
                                    break;

                                default:
                                    break;

                            }
                        }
                }

    }

    protected void GetDetail()
    {
        string str = "select content from content where list_id=" + list_id;
        dt = da.GetTable(str);
        if(dt.Rows.Count > 0)
        {
            string content = Server.HtmlDecode(Server.HtmlDecode(dt.Rows[0]["content"].ToString()));
            DepLB.Text = content;
        }        
    }
}
--------------------编程问答--------------------
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,