| 加入收藏| 设为首页| 联系我们

首页 站长学习 站长之家 源码下载 建站素材 书籍教程 常用工具
 您现在的位置: 动力中国 >> 网络编程 >> Ajax教程 >> 文章正文  
 Ajax+GridView+Xml的简易留言薄
 

Ajax+GridView+Xml的简易留言薄

http://www.domcn.org  文章来源:本站收藏  点击数:

  关键字:Ajax+GridView+Xml的简易留言薄

aspx文件
  <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %>

<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head id=Head1 runat=server>
    <title>无标题页</title>
 
</head>
<body>
    <form id=form1 runat=server>
    <div>
        <asp:ScriptManager ID=ScriptManager1 runat=server>
        </asp:ScriptManager>
   
    </div>
        <asp:UpdatePanel ID=UpdatePanel1 runat=server>
            <ContentTemplate>
                <asp:GridView ID=GridView1 runat=server CellPadding=0 ForeColor=#333333 GridLines=None AllowPaging=True AutoGenerateColumns=False Width=100% OnPageIndexChanging=GridView1_PageIndexChanging PageSize=5 BorderStyle=Solid BorderWidth=1px>
                    <Columns>
                    <asp:TemplateField>
                    <HeaderStyle Width=100% />
                    <ItemTemplate>
                      <table border=0 cellpadding=2 cellspacing=1>
                        <tr>
                        <td>用户姓名:<%#Eval(name) %>留言时间:<%#Eval(sdate)%></td>
                        </tr>
                        <tr><td><hr width=100% color=green/></td></tr>
                        <tr><td>留言内容:<%#Eval(couent)%></td></tr>
                      </table>
                    </ItemTemplate>
                    </asp:TemplateField>
                    </Columns>
                    <PagerStyle HorizontalAlign=Right />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
        &nbsp; &nbsp;&nbsp;
        <asp:UpdatePanel ID=UpdatePanel2 runat=server>
            <ContentTemplate>
            <table>
            <tr><td style=width: 306px>姓名
                <asp:TextBox ID=TextBox1 runat=server Width=144px ></asp:TextBox></td></tr>
                <tr><td style=width: 306px; height: 77px>   留言内容
                <asp:TextBox ID=TextBox2 runat=server TextMode=MultiLine Width=223px Height=109px></asp:TextBox></td></tr>
             <tr><td colspan=2>  <asp:Button ID=Button1 runat=server OnClick=Button1_Click Text=提交 SkinID=o /></td></tr>
             
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
  cs文件
  using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindData();
        }
    }
    private void BindData()
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(XMLFile.xml));
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet(my);
        ds.ReadXml(Server.MapPath(XMLFile.xml));//读取xml文件
        DataRow dr = ds.Tables[0].NewRow();
        dr[name] = TextBox1.Text.ToString();
        dr[couent] = TextBox2.Text.ToString();
        dr[sdate] = DateTime.Now;
        ds.Tables[0].Rows.Add(dr);
        ds.WriteXml(Server.MapPath(XMLFile.xml));//写入xml文件
        Response.Redirect(default.aspx);
       
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindData();
    }
}
  xml文件
  <?xml version=1.0 standalone=yes?>
<person>
  <user>
    <name>xiaoxiao</name>
    <couent>xiaoxoao</couent>
    <sdate>2006-11-14 21:06:14</sdate>
  </user>
</person>
 在此下载代码http://www.cnblogs.com/Files/TeaGreen/liuyanbo.rar


Ajax+GridView+Xml的简易留言薄
  • 上一篇文章:

  • 下一篇文章:
  •  热门文章
    普通文章 电子邮件改头换面 四公司畅谈未
    普通文章 PC病毒史上最声名狼藉的八大病
    普通文章 Rails系统中的AJAX开发技术简析
    普通文章 基于ASP.NET AJAX框架实现表单
    普通文章 开发ASP.NET AJAX客户端定制行
    普通文章 用JFreeChart对JSP报表进行增强
    普通文章 SQL Server 2005上的CLR和ADO.
    普通文章 SQL Server 2005的XML支持机制
    普通文章 Firefox中标签式浏览技巧大全
    普通文章 Tomcat中的Session和Cookie大揭
     
     推荐文章
    推荐文章 把Google地图嵌入网页 就是这么
    推荐文章 迅雷搜索候选资源出错的解决
    推荐文章 轻松去除迅雷里的各种广告和资
    推荐文章 突破限制 免费领养到QQ空间五级
    推荐文章 Rational统一过程RUP贴近中小软
    推荐文章 构建自己的轻量级XML DOM分析程
    推荐文章 WPS Office 2007技巧:妙用配置
    推荐文章 Excel 2007:求余数函数实用进阶
    推荐文章 浅谈ASP.NET的Postback
    推荐文章 软件开发中项目需求管理简述
     
     相关文章
    没有相关文章
    设为首页 | 加入收藏 | 广告合作 | 联系站长 | 版权申明 |
    动力中国为网友提供免费学习资料,可用资源,如果您认为我们的相关内容侵害到了您的权利请联系管理员
    Copyright © 2006-2008 domcn.org All Rights Reserved.