protected void Page_Load(object sender, EventArgs e) { //初始化内容分页 ArrayList contents = new ArrayList(); contents.Add(""); //保存到ViewState ViewState["contentPages"] = contents; //绑定文章内容分页 Bind_ContentPage(); } } #region 文章内容分页相关 /// <summary> /// 绑定内容分页 /// </summary> /// <param name="seleteMax">是否选中下拉列表的最大值`</param> private void Bind_ContentPage() { this.DrpPage.Items.Clear(); ArrayList contents = ViewState["contentPages"] as ArrayList; for (int i = 1; i <= contents.Count; i++) { ListItem item = new ListItem(); item.Text = i.ToString(); item.Value = i.ToString(); this.DrpPage.Items.Add(item); } int pIndex = DrpPage.Items.Count - 1; this.DrpPage.SelectedIndex = pIndex; //把当前的页码放在ViewState中 ViewState["pIndex"] = pIndex.ToString(); if (this.DrpPage.Items.Count == 1) this.cmdDelPage.Enabled = false; else this.cmdDelPage.Enabled = true; this.FCKeditor1.Focus(); } /// <summary> /// 添加新页 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void cmdAddPage_Click(object sender, EventArgs e) { ArrayList contents = ViewState["contentPages"] as ArrayList; //添加新页 contents.Add(""); //保存到ViewState ViewState["contentPages"] = contents; //保存当前页面的数据 cmdSave_Click(sender, e); //重新绑定分页下拉列表 Bind_ContentPage(); this.FCKeditor1.Value = ""; } /// <summary> /// 删除页码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void cmdDelPage_Click(object sender, EventArgs e) { ArrayList contents = ViewState["contentPages"] as ArrayList; int i = int.Parse(ViewState["pIndex"].ToString()); //移除制定的内容页 contents.RemoveAt(i); //保存到ViewState ViewState["contentPages"] = contents; //重新绑定分页下拉列表 Bind_ContentPage(); this.FCKeditor1.Value = ""; //绑定最新页面的值 int pIndex = int.Parse(ViewState["pIndex"].ToString()); if (i > pIndex) i = pIndex; this.DrpPage.SelectedIndex = i; ViewState["pIndex"] = i; this.FCKeditor1.Value = contents[i].ToString(); } /// <summary> /// 保存当前页面的数据,放到数组中 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void cmdSave_Click(object sender, EventArgs e) { ArrayList contents = ViewState["contentPages"] as ArrayList; //获取当前页数 int i = int.Parse(ViewState["pIndex"].ToString()); //把当前的页数的内容放入集合中 contents[i] = this.FCKeditor1.Value; //保存到ViewState ViewState["contentPages"] = contents; } //当页码发生变化时 呈现当前页面的数据 protected void DrpPage_SelectedIndexChanged(object sender, EventArgs e) { ArrayList contents = ViewState["contentPages"] as ArrayList; int pIndex = int.Parse(ViewState["pIndex"].ToString()); contents[pIndex] = FCKeditor1.Value; //获取当前页数的 int i = int.Parse(this.DrpPage.SelectedValue) - 1; //把已经保存的当期页面的值放在文本编辑器中 this.FCKeditor1.Value = contents[i].ToString(); ViewState["pIndex"] = i.ToString(); this.FCKeditor1.Focus(); } #endregion 页面上的元素 <td> <div> 选择页数: <asp:DropDownList ID="DrpPage" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DrpPage_SelectedIndexChanged"> </asp:DropDownList> <asp:Button ID="cmdAddPage" runat="server" Text="添加新页" OnClick="cmdAddPage_Click" /> <asp:Button ID="cmdDelPage" runat="server" Text="删除页数" OnClick="cmdDelPage_Click" /> <asp:Button ID="cmdSave" runat="server" Text="保存" OnClick="cmdSave_Click" /> </div> <FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" Value="" Height="500px" Width="620px" BasePath="/WebEditor/fckeditor/"> </FCKeditorV2:FCKeditor> <%--<iframe style="width:620px; float:left;" src="../EditV1.0/Edit/editor.htm?id=TxtContent" frameborder="0"></iframe> <div style="display: none;"> <asp:TextBox ID="TxtContent" runat="server" TextMode="MultiLine" Height="95px" Width="293px"></asp:TextBox> </div>--%> </td>