DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> Ajax+GridView+Xml的簡易留言薄
Ajax+GridView+Xml的簡易留言薄
編輯:AJAX詳解     

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>
            
        <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" 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>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved