|
为了显示一些Html超文本内容,用代码生成内容,放在ContentPanel容器,借助LiteralControl控件来实现,首先页面初始化后生成 的内容,后来需要更新新的内容,借助Button事件来更新,但效果未能达到!代码如下:
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Exam.aspx.cs" Inherits="WebJazz.Exam" %><!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 runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <x:PageManager ID="PageManager1" runat="server" />
- <x:ContentPanel ID="ContentPanel1" runat="server" BodyPadding="5px" ShowBorder="true"
- ShowHeader="true" Title="ContentPanel">
- <asp:Literal ID="lc" runat="server"></asp:Literal>
- </x:ContentPanel>
- <x:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click">
- </x:Button>
- </form>
- </body>
- </html>
-
复制代码- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Text;
- using FineUI;
- namespace WebJazz
- {
- public partial class Exam : System.Web.UI.Page
- {
- int[] StatValue = new int[] { 100, 200 };
- protected void Page_Init(object sender, EventArgs e)
- {
- FillStatCont(StatValue);
- }
- protected void FillStatCont(int[] StatValue)
- {
- LiteralControl lc = new LiteralControl();
- lc.ID = "Stat";
- StringBuilder htmlStr = new StringBuilder();
- htmlStr.Append("<div class=article_col>");
- htmlStr.Append("<div class=article_label style='width:40px'></div>");
- htmlStr.Append("<div class=article_content>合计</div>");
- htmlStr.Append("</div>");
- for (int i = 0; i < StatValue.Length; i++)
- {
- htmlStr.Append("<div class=article_col>");
- htmlStr.Append("<div class=article_content>" + StatValue[i] + "</div>");
- htmlStr.Append("</div>");
- }
- lc.Text = htmlStr.ToString();
- ContentPanel1.Controls.Add(lc);
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- StatValue[0] = 400;
- StatValue[1] = 600;
- FillStatCont(StatValue);
- }
- }
- }
复制代码 本来想实现统计结果在Grid的下方,如下图:
现贴出可测试的代码,请大师们帮助解决!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|