白分求有价值的Repeater的代码和精辟的介绍,很快结帖子!!!!!此外小问 if (!this.IsPostBack)的作用和用法!!!

解决方案 »

  1.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=54F4C732-AAE2-4135-FB1B-7B4B613BAA33
      

  2.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=D5C6E29D-99F5-44E8-4FED-75AF892A53CB
      

  3.   

    IsPostBack参考
    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemwebuiusercontrolclassispostbacktopic.asp
      

  4.   

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;326338#1
    Repeater控件嵌套的使用方法(当然也包含普通使用方法了)
    if (!this.IsPostBack)
    {
      //
    }
    表示页面是第一次载入,此时没有接受过任何的post过来的数据
      

  5.   

    IsPostBack
    指示是正为响应客户端回发而加载用户控件,还是正第一次加载和访问用户控件。
      

  6.   

    在首次登陆一个页面的时候,如果页面在第一次加载时就有一些绑定的数据呈现,那么如果   此页面又有对数据的其他操作,比如删除,修改等,那么一定要在Pageload 事件中采用                           if  (!Page.Ispostback)  {  数据绑定}           因为在每次网页提交给服务器时,PageLoad事件都会重新触发,导致反复绑定初始值,然后才进入我们需要的CLICK事件等,这样将使得一些重要信息,比如存储的session值丢失或错乱。当我们加入 if  (!Page.Ispostback),它表明了只有网页在第一次加载时才执行的数据绑定,当我们单击一个修改或删除按钮,网页提交到服务器,我们通过断点调试可看到,当执行到PageLoad事件时,开始判断 if  (!Page.Ispostback),发现并非首次加载此页面,程序自动转到修改或删除的CLICK事件中了。有效的控制了程序的运行。
      

  7.   

    IsPostBack
    指示是正为响应客户端回发而加载用户控件,还是正第一次加载和访问用户控件。
      

  8.   

    <%@ Page language="c#" Codebehind="ICPlanEdit.aspx.cs" AutoEventWireup="false" Inherits="ICAudit.ICPlanEdit" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>ICPlan</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <LINK href="../css/style.css" type="text/css" rel="stylesheet">
    <script language="javascript" src="../js/formcheck.js"></script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <table style="WIDTH: 739px; HEIGHT: 366px" align="center" border="0">
    <TBODY>
    <tr>
    <td colspan="5" align="center"><IMG src="../images/iczhbj.gif" border="0"></td>
    </tr>
    <tr>
    <td align="left">
    计划描述信息:<asp:TextBox id="PlanDescript" runat="server" MaxLength="50"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>编制单位:大连市信息产业局
    </td>
    </tr>
    <tr>
    <td valign="top" style="HEIGHT: 186px">
    <asp:Repeater id="RepeaterICPlan" runat="server">
    <HeaderTemplate>
    <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bordercolorlight="#003366"
    bordercolordark="#FFFFFF">
    <tr>
    <td style="WIDTH: 33px">
    编号
    </td>
    <td style="WIDTH: 61px">
    单位<br>
    名称
    </td>
    <td style="WIDTH: 51px">
    所有制<br>
    性质
    </td>
    <td style="WIDTH: 61px">
    主营业务及重点产品
    </td>
    <td style="WIDTH: 56px">
    注册资本
    </td>
    <td style="WIDTH: 53px">
    项目名称
    </td>
    <td style="WIDTH: 53px">
    计划总投<br>
    资额(万元)
    </td>
    <td>
    实际投资<br>
    额(万元)
    </td>
    <td>
    申请金额<br>
    (万元)
    </td>
    <td>
    计划金额<br>
    (万元)
    </td>
    <td>
    批准金额<br>
    (万元)
    </td>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"projectNo")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"projectunit")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"ownercode")%>
    &nbsp;
    </td>
    <td style="WIDTH: 88px">
    <%# DataBinder.Eval(Container.DataItem,"mainbussiness")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"registmoney")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"projectname")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"jhztzZj")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"xmytzZj")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"bnysqzxzjZj")%>
    &nbsp;
    </td>
    <td>
    <%# DataBinder.Eval(Container.DataItem,"PlanNumber")%>
    &nbsp;
    </td>
    <td>
    <asp:TextBox Runat=server ID="allowMoney" text='<%# DataBinder.Eval(Container.DataItem,"AllowMoney")%>' Width=50>
    </asp:TextBox>
    <asp:RequiredFieldValidator id="NumRequired" runat="server" ControlToValidate="allowMoney" ErrorMessage="* 批准金额不可为空"
    Display="Dynamic">
    *
    </asp:RequiredFieldValidator>
    <asp:CompareValidator id="valdeclaredate" runat="server" ControlToValidate="allowMoney" ValueToCompare="0"
    Operator="GreaterThan" Type="double" ErrorMessage="* 批准金额必须输入大于0的数字!" Display="dynamic">
    *
    </asp:CompareValidator>
    <input type=hidden id="ApplyId" runat=server value='<%# DataBinder.Eval(Container.DataItem,"ID")%>' NAME="ApplyId">
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    <tr>
    <td>&nbsp;
    </td>
    <td align="center">
    合计
    </td>
    <td>--
    </td>
    <td>--
    </td>
    <td>--
    </td>
    <td>--
    </td>
    <td>--
    </td>
    <td>--
    </td>
    <td><asp:label id="NeedNum" runat="server"></asp:label>&nbsp;
    </td>
    <td><asp:label id="PlanNum" runat="server"></asp:label>&nbsp;
    </td>
    <td>--
    </td>
    </tr>
    <tr>
    <td colspan="11">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 制表人:
    <asp:Label id="Oper" runat="server">Label</asp:Label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 制表时间:
    <asp:Label id="Finishtime" runat="server">Labe2</asp:Label>
    </td>
    </tr>
    </table>
    </FooterTemplate> </asp:Repeater></TD></TR>
    <tr>
    <td align="center">
    <asp:ImageButton id="ImageButton1" runat="server" ImageUrl="../images/queding.gif" CssClass="ImgButton"></asp:ImageButton>
    <asp:ImageButton id="ImageButton2" runat="server" ImageUrl="../images/quxiao.gif" CssClass="ImgButton"></asp:ImageButton>
    </td>
    </tr>
    </TBODY></TABLE>
    <asp:ValidationSummary id="ValidationSummary1" runat="server" ShowMessageBox="True" ShowSummary="False"
    DisplayMode="List"></asp:ValidationSummary></form>
    <script language="javascript">
    function check()
    {
    if(!checkEmpty("PlanDescript","计划描述信息"))
    {
    return false;
    }
    return true;
    }
    </script>
    </body>
    </HTML>
      

  9.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;
    using dhc.dataBase;
    using dhc.com;
    using dhc.log;
    using BPOLib;
    using BPWBLib;namespace ICAudit
    {
    /// <summary>
    /// ICPlan 的摘要说明。
    /// </summary>
    public class ICPlanEdit : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.ImageButton ImageButton1;
    protected System.Web.UI.WebControls.ImageButton ImageButton2;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.TextBox PlanDescript;
    protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
    protected System.Web.UI.WebControls.Repeater RepeaterICPlan;


    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!this.IsPostBack)
    {
    initGrid();
    ImageButton1.Attributes.Add("onclick","if (!check()) return false;");
    }
    }
    private bool initGrid()
    {
    dbConn conn = new dbConn();
    try
    {
    conn.openDB("Conn");
    string strPlanId = Request["Id"];
    string strSql="select * from IcPlan where Id = '"+strPlanId+"'";

    DataSet ds = conn.getDataSet(strSql,"Plan");
    if (ds.Tables["Plan"].Rows.Count > 0)
    {
    DataRow row = ds.Tables["Plan"].Rows[0];
    PlanDescript.Text = row["Descript"].ToString();  

    }
    strSql = "select a.ID,a.projectNo,a.projectname,a.projectunit,a.registmoney,a.mainbussiness,a.ownercode,a.jhztzZj,a.xmytzZj,a.bnysqzxzjZj,a.AllowMoney,b.PlanNumber from icDeclare a,eProcessDB.dbo.XXCYJ_IC b where PlanId = '"+strPlanId+"' and a.ID=b.ApplyId";
    OleDbDataReader dbRead= conn.getDataReader(strSql);
    RepeaterICPlan.DataSource = dbRead;
    RepeaterICPlan.DataBind();
    dbRead.Close();
    return true;
    }
    catch
    {
    Response.Write("发生错误!");
    return false;
    }
    finally
    {
    conn.closeConn();
    }

    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.RepeaterICPlan.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.RepeaterICPlan_ItemDataBound);
    this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    dbConn conn = new dbConn();
    try
    {
    conn.openDB("Conn");
    conn.beginTrans(); string strPlanId = Request["Id"];
    string strSql="select * from IcPlan where Id = '"+strPlanId+"'";
    DataSet ds = conn.getDataSet(strSql,"Plan");
    if (ds.Tables["Plan"].Rows.Count > 0)
    {
    DataRow row = ds.Tables["Plan"].Rows[0];
    row["Descript"] =  PlanDescript.Text;
                        row["Oper"]=Session["NAME"].ToString();
    row["Finishtime"]=publicFunction.getStandardDate(DateTime.Now.ToString());
    conn.UpdateDataset("Plan",1);
    } int iCount = RepeaterICPlan.Items.Count;
    for (int i=0;i<iCount;i++)
    {
    HtmlInputHidden hihID = (HtmlInputHidden)RepeaterICPlan.Items[i].FindControl("ApplyId");
    TextBox tbAllowMoney = (TextBox)RepeaterICPlan.Items[i].FindControl("allowMoney");
    strSql = "select ID,AllowMoney,PlanId from icDeclare where ID = '"+hihID.Value+"'";
    ds = conn.getDataSet(strSql,"IC");
    if (ds.Tables["IC"].Rows.Count > 0)
    {
    DataRow row = ds.Tables["IC"].Rows[0];
    row["AllowMoney"] = tbAllowMoney.Text;
    conn.UpdateDataset("IC",1);
    }
    }
    conn.commitTrans();
    Response.Write("<script language='javascript'>");
    Response.Write("alert('信息成功保存');");
    Response.Write("window.location.replace('IcPlanList.aspx');"); 
    Response.Write("</script>");
    }
    catch
    {
    conn.rollbackTrans();
    Response.Write("发生错误!");
    }
    finally
    {
    conn.closeConn();
    }
    } private void RepeaterICPlan_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {  
    if (e.Item.ItemType == ListItemType.Footer)
    {
    Label labOper = (Label)e.Item.FindControl("Oper");
    labOper.Text = Session["NAME"].ToString(); Label labFinishtime = (Label)e.Item.FindControl("Finishtime");
    labFinishtime.Text = publicFunction.getStandardDate(DateTime.Now.ToString());
    dbConn conn= new dbConn();
    try
    {
    conn.openDB("Conn"); 
    string strPlanId = Request["Id"];
    string strsql="select sum(a.bnysqzxzjZj) NeedNum,sum(b.PlanNumber) PlanNum from icDeclare a,eProcessDB.dbo.XXCYJ_IC b where PlanId = '"+strPlanId+"' and a.ID=b.ApplyId";

    OleDbDataReader dbReader = conn.getDataReader(strsql); 
    if (dbReader.Read())
    {
    Label labNeedNum = (Label)e.Item.FindControl("NeedNum");
    labNeedNum.Text = dbReader["NeedNum"].ToString(); Label labPlanNum = (Label)e.Item.FindControl("PlanNum");
    labPlanNum.Text = dbReader["PlanNum"].ToString();
    }
    }
    catch
    {
    Response.Write("发生错误!");
    return;
    }
    finally
    {
    conn.closeConn();
    }
    }
    }
    }
    }
      

  10.   

    第一个是aspx文件 第二个是cs文件 是很好的例子
      

  11.   

    Page.Ispostback返回一个Bool型的值,如果是第一次开打网面返回false如果是控件行为返的页面返回true值!!