您的位置:首页 > 移动开发

Asp.net窄屏页面 手机端新闻列表

2015-07-17 14:11 211 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchNotice.aspx.cs" Inherits="SignetPortal.Views.Mobile.SerchNotice" %>

<%@ Import Namespace="SignetPortal.Share.UnClass" %>
<%@ Import Namespace="SignetPortal.Share.AllHelper" %>
<!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 id="Head1" runat="server">
<title></title>
<meta name="viewport" content="width=device-width" />
<link href="../../Scripts/bootstrap-3.3.2-dist/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<script src="../../Scripts/bootstrap-3.3.2-dist/js/jquery-1.11.2.js" type="text/javascript"></script>
<script src="../../Scripts/bootstrap-3.3.2-dist/js/bootstrap.js" type="text/javascript"></script>
<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" type="text/ecmascript"></script>
<script type="text/javascript">
function show(obj) {
window.location.href = "Notice.aspx?" + obj;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="CompanyId" name="CompanyId" type="hidden" value="" maxLength="100" title="企业编码" />
<div class="list-group">
<%--        <a href="#" class="list-group-item active">
<asp:Label ID="labNoticeSection" runat="server"></asp:Label></a>--%>
<asp:Repeater ID="Rpdata" runat="server">
<ItemTemplate>
<a href="#" onclick="show('<%# AspNetPage.SetQueryString("NoticeId",Eval("NoticeId").ToString())%>')"
class="list-group-item">
<%# Eval("NoticeTitle").ToString().Length > 16? Eval("NoticeTitle").ToString().Substring(0, 16) + "..." : Eval("NoticeTitle").ToString()%>
</a>
</ItemTemplate>
</asp:Repeater>
</div>
<nav>
<ul class="pager">
<li><asp:LinkButton ID="lbtnpritPage" runat="server" OnClick="lbtnpritPage_Click">上一页</asp:LinkButton></li>
<li><asp:LinkButton ID="lbtnNextPage" runat="server" OnClick="lbtnNextPage_Click">下一页</asp:LinkButton></li>
</ul>
</nav>
</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;

namespace SignetPortal.Views.Mobile
{
public partial class SerchNotice : System.Web.UI.Page
{
/// <summary>
/// 创建分页数据源的对象
/// </summary>
protected PagedDataSource psd = new PagedDataSource();
protected static int PageIndex = 0;

protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 通过 url 获取地域编码
/// </summary>
/// <returns></returns>
protected static string GetArea()
{
System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;
string area = "1301";
if (page != null)
{
string queryString = System.Web.HttpContext.Current.Request.QueryString["area"].ToString();

//string queryString = System.Web.HttpContext.Current.Request.Url.Query;
//queryString.Substring(queryString.Length - 4);

area = queryString;
if (area != "1308" && area != "1311" && area != "1307" && area != "1306" && area != "1305" && area != "1301")
{
area = "1301";
}

}
return area;
}

protected void Page_PreRender(object sender, EventArgs e)
{
Session["CityId"] = GetArea();
if (Session["CityId"] == null)
{
Response.Redirect("Index.aspx", false);
return;
}
if (!Page.IsPostBack)
{
BindNotice(sender, e);
}
}
private void BindNotice(object sender, EventArgs e)
{
try
{
string noticeSection = Request.QueryString["NoticeSection"].ToString();
string cityId = "1301";
if (Session["CityId"] != null)
{
cityId = Session["CityId"].ToString();
}
Share.UnClass.PageExerciser pv = new Share.UnClass.PageExerciser();
DataTable dt = Logic.Bll.News.SearchNotice(pv, noticeSection, cityId);
if (dt != null)
{
psd.AllowPaging = true;
psd.PageSize = 5;
//获取总页数
int pageCount = dt.Rows.Count % 5 == 0 ? dt.Rows.Count / 5 : dt.Rows.Count / 5 + 1;

if (sender is int && PageIndex > 0 && pageCount > 1)
{
PageIndex--;

}
else if (sender is string && (PageIndex + 1) < pageCount)
{
PageIndex++;
}

psd.CurrentPageIndex = PageIndex;

psd.DataSource = dt.DefaultView;
Rpdata.DataSource = psd;
Rpdata.DataBind();

//Rpdata.DataSource = dt;
//Rpdata.DataBind();
}
}
catch (Exception ex)
{
}
}

protected void lbtnpritPage_Click(object sender, EventArgs e)
{
sender = -1;
}

protected void lbtnNextPage_Click(object sender, EventArgs e)
{
sender = "Next";
this.BindNotice(sender, e);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: