日期:2014-05-17  浏览次数:20475 次

repeater控件与AspNetPager结合 AspNetPager不显示
代码如下,求大神们帮助啊!!!
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;
using System.Text;
using Wuqi.Webdiyer;

namespace MeApp
{

   
  public partial class weathedit : System.Web.UI.Page
  {
  int id = 0;
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  BindGrid();
  //bindData(); //使用url分页,只需在分页事件处理程序中绑定数据即可,无需在Page_Load中绑定,否则会导致数据被绑定两次
  }
  }
  private void BindGrid()
  {
  string settings = ConfigurationManager.AppSettings["ConStr"].ToString();
  //Response.Write(settings);
  //Response.End();
  SqlConnection sqlCon = new SqlConnection(settings);
  sqlCon.Open(); //打开数据库连接
  string sqlstr = "select * from WeatherInfo";
  SqlCommand mycmd = new SqlCommand(sqlstr, sqlCon);//创建数据库命令
  SqlDataReader mydr = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
  //Repeater数据控件绑定
  rptUser.DataSource = mydr;//指定数据源
  rptUser.DataBind();//绑定到指定的数据源
  }

  protected void rptUser_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  {
  System.Data.Common.DbDataRecord record = (System.Data.Common.DbDataRecord)e.Item.DataItem;
  int userId = int.Parse(record["weinfo_id"].ToString());
  if (userId != id)
  {
  ((Panel)e.Item.FindControl("plItem")).Visible = true;
  ((Panel)e.Item.FindControl("plEdit")).Visible = false;
  }
  else
  {
  ((Panel)e.Item.FindControl("plItem")).Visible = false;
  ((Panel)e.Item.FindControl("plEdit")).Visible = true;
  }
  }
  }

  protected void rptUser_ItemCommand(object source, RepeaterCommandEventArgs e)
  {
  if (e.CommandName == "Edit")
  {
  id = int.Parse(e.CommandArgument.ToString());
  }
  else if (e.CommandName == "Cancel")
  {
  id = -1;
  }
  else if (e.CommandName == "Update")
  {
  string weatherdate = ((TextBox)this.rptUser.Items[e.Item.ItemIndex].FindControl("txtdate")).Text.Trim();
  string weathertime = ((TextBox)this.rptUser.Items[e.Item.ItemIndex].FindControl("txttime")).Text.Trim();
  string weath = ((TextBox)this.rptUser.Items[e.Item.ItemIndex].FindControl("txtweather")).Text.Trim();
  string tem = ((TextBox)this.rptUser.Items[e.Item.ItemIndex].FindControl("txttem")).Text.Tr