<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageLoadData.aspx.cs" Inherits="PageLoadData" %>
<!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">
<div style="text-align :center; background-color: White">
<table id="Table1" style="background-color:#DEBA84;width:749px" border="0" cellpadding="4" cellspacing="1"
>
<tr>
<td style="background-color: #DEBA84; height: 32px">
您的大名</td>
<td style="background-color: #DEBA84; width: 508px; height: 32px">
<asp:TextBox ID="txtName" runat="server"
MaxLength="10" Width="519px"></asp:TextBox></td>
</tr>
<tr>
<td style="background-color: #DEBA84;" colspan="1" rowspan="1" >
E-Mail</td>
<td style="background-color:#DEBA84; width: 505px" >
<p>
<asp:TextBox ID="txtEmail" runat="server"
MaxLength="30" Width="519px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" ErrorMessage="电子邮件格式不正确"
ValidationExpression="/w+([-+.']/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*"></asp:RegularExpressionValidator>
</p>
</td>
</tr>
<tr>
<td style="background-color:#DEBA84" colspan="1" rowspan="1">
内容</td>
<td style="background-color:#DEBA84; width: 505px">
<p>
<asp:TextBox ID="txtContent" runat="server" Height="160px"
TextMode="MultiLine" Width="519px"></asp:TextBox></p>
</td>
</tr>
</table>
<p >
<asp:RadioButtonList ID="radioList" runat="server" AutoPostBack="True"
onselectedindexchanged="radioList_SelectedIndexChanged" Width="149px"
RepeatLayout="Flow" ToolTip="请选择数据库类型">
<asp:ListItem>XML数据库</asp:ListItem>
<asp:ListItem>Access数据库</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click"
Text=" 提 交(S)" Enabled="False" AccessKey="S" ToolTip="快捷键(Alt+S)"
Font-Size="Medium" Height="32px" Width="100px" />
<asp:Button ID="btnView" runat="server" OnClick="btnView_Click" Text="查 看(V)"
Width="100px" Enabled="False" AccessKey="V" ToolTip="快捷键(Alt+V)"
Font-Size="Medium" Height="32px" /></p>
</div>
<asp:ScriptManager ID="ScriptManagerTitle" runat="server">
</asp:ScriptManager>
<asp:Timer ID="TimerTitle" runat="server" Interval="300"
ontick="TimerTitle_Tick" Enabled="False">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanelTitle" runat="server">
<ContentTemplate>
<asp:Label ID="LabelTime" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerTitle" EventName="Tick">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
using System;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
public partial class PageLoadData : System.Web.UI.Page
{
#region Page_Load
private static DataTable dataTable;
private static StringBuilder sbTitle;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dataTable = UserSchema.UserTable;
sbTitle = new StringBuilder("符合的格式规范");
TimerTitle.Enabled = true;
}
}
#endregion
#region location.href
protected void btnView_Click(object sender, EventArgs e)
{
Response.Write("<script>window.top.location.href='PageSaveData.aspx'</script>");
}
#endregion
#region AddRow
protected void btnSubmit_Click(object sender, EventArgs e)
{
DataRow row = dataTable.NewRow();
try
{
row.SetField<string>("UserName", txtName.Text);
row.SetField<string>("UserEmail", txtEmail.Text);
row.SetField<string>("Content", txtContent.Text);
row.SetField<DateTime>("SendTime", DateTime.Today);
dataTable.Rows.Add(row);
foreach (TextBox text in Form.Controls.OfType<TextBox>())
{
text.Text = null;
}
}
catch (Exception se)
{
Response.Write(se.Message);
row.ClearErrors();
}
}
#endregion
#region DataSource
protected void radioList_SelectedIndexChanged(object sender, EventArgs e)
{
switch (radioList.SelectedIndex)
{
case 0:
FileInfo info = new FileInfo(Server.MapPath("~/App_Data/User.xml"));
if (info.Exists)
using (StreamReader reader = info.OpenText())
{
dataTable.Clear();
dataTable.ReadXml(reader);
}
break;
case 1:
OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder();
builder.Provider = "Microsoft.ACE.OLEDB.12.0";
builder.DataSource = @"|DataDirectory|/User.accdb";
builder["Jet OLEDB:Database Password"] = "jinzhexian";
using (OleDbDataAdapter adapter = new OleDbDataAdapter("select * from [User]", builder.ConnectionString))
{
dataTable.Clear();
dataTable.BeginLoadData();
adapter.Fill(dataTable);
dataTable.EndLoadData();
}
break;
}
btnSubmit.Enabled = btnView.Enabled = true;
Session["Title"] = radioList.SelectedValue;
Page.Title = null;
}
#endregion
protected void TimerTitle_Tick(object sender, EventArgs e)
{
LabelTime.Text = string.Format("{0:F}", DateTime.Now);
}
}