国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

用asp.net寫的論壇程序--論壇主頁

2024-07-10 13:07:58
字體:
來源:轉載
供稿:網友
注冊會員,創建你的web開發資料庫,1) forum.aspx :- the main forum page

<%@ page language="c#" debug="true" %>
<%@ assembly name="system.data" %>
<%@ import namespace="system.data.ado" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system" %>
<html><head>
<title>welcome to my forum!</title>
<script language="c#" runat="server" >
//execute this script when the page loads
void page_load(object src, eventargs e)
{
//call the method to databind the datagrid
binding() ;
}
//this method connects to the database, and databinds the database to the datagrid
public void binding()
{
//string to connect to the database, if your database is in some other directory then change the path
//to the database below
string [email protected]"provider=microsoft.jet.oledb.4.0 ;data source="+server.mappath(".//db//board.mdb") ;
//make a connection to the database
adoconnection myconn = new adoconnection(strconn) ;
//string to select records from the database. newpost table
//i have used "order by postid desc" since i want to show the latest post on the top
//if you remove this clause then the oldest message will be shown first
string strcom = "select postid ,subject ,name ,replies ,views ,date from newpost order by postid desc" ;
//open the connection, always remember to open the connection before doing anything else
myconn.open();
dataset mydataset = new dataset();
//create a adodatasetcommand and a dataset
adodatasetcommand mycommand =new adodatasetcommand(strcom,myconn);
//fill the dataset
mycommand.filldataset(mydataset,"newpost") ;
//connection is closed
myconn.close();
//set the dataview of the table "newpost" contained in the dataset for the datagrid
datagrid1.datasource = mydataset.tables["newpost"].defaultview ;
//databind the datagrid
datagrid1.databind();
}
//this method is called when the datagrid is paged (i.e. when you change from page 1 to page 2 etc.. )
public void datagrid_updt(object sender, datagridpagechangedeventargs e)
{
//call the method to databind
binding();
}
//this method is called when the form is submitted to make a new post
public void submit_click(object sender, eventargs e)
{
//proceed only if all the required fields are filled-in
if(page.isvalid&&name.text!=""&&subject.text!=""&&email.text!=""){
//get the current date and time
datetime now = datetime.now ;
errmess.text="" ;
//i am building a custom query which will be used to call the postmessage.aspx page.
//since it will be a query we have to encode the query into utf8 format.
//so i get all the fields from the form and encode them into utf8 format
string req = "name="+ system.web.httputility.urlencodetostring(name.text, system.text.encoding.utf8);
req+="&&email="+ system.web.httputility.urlencodetostring(email.text, system.text.encoding.utf8);
req+="&&subject="+ system.web.httputility.urlencodetostring(subject.text, system.text.encoding.utf8);
//get the hostaddress of the author
req+="&&ip="+ system.web.httputility.urlencodetostring(request.userhostaddress.tostring(), system.text.encoding.utf8);
req+="&&date="+ system.web.httputility.urlencodetostring(now.tostring(), system.text.encoding.utf8);
req+="&&message="+ system.web.httputility.urlencodetostring(message.text, system.text.encoding.utf8);
//a 'yes' is used below to tell the postmessage page that this is a new topic post
req+="&&newpost="+ system.web.httputility.urlencodetostring("yes", system.text.encoding.utf8);
//call the postmessage.aspx page and append the query to it.
page.navigate("postmessage.aspx?" + req);
}
else
{
errmess.text="fill in all the required fields before posting!<br>" ;
}
}
</script>
<link href="mystyle.css" type=text/css rel=stylesheet></head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<!-- #include file="header.inc" -->
<center>
<asp:label id="errmess" text="" runat="server" />
<asp:label class=fodark text="<font color=#00000 >welcome to my discussion forum</font>" runat=server />
<br>
<br>
<form method="post" runat="server" id=form1>
<%-- the datagrid settings. its very interesting how much you can play with it --%>
<asp:datagrid id=datagrid1 runat="server" forecolor="black"
pagerstyle-mode="numericpages"
onpageindexchanged="datagrid_updt" pagesize="20" allowpaging="true" width="80%" autogeneratecolumns="false">
<property name="pagerstyle">
<asp:datagridpagerstyle backcolor="coral" mode="numericpages">
</asp:datagridpagerstyle>
</property>

<property name="alternatingitemstyle">
<asp:tableitemstyle bordercolor="#ffc080" backcolor="#ff9966">
</asp:tableitemstyle>
</property>

<property name="footerstyle">
<asp:tableitemstyle forecolor="white" backcolor="darkorange">
</asp:tableitemstyle>
</property>

<property name="itemstyle">
<asp:tableitemstyle backcolor="moccasin">
</asp:tableitemstyle>
</property>

<property name="headerstyle">
<asp:tableitemstyle font-bold="true" forecolor="white" backcolor="coral">
</asp:tableitemstyle>
</property>
<%-- i am setting up the individual columns myself using templates --%>
<property name="columns">
<%-- manipulate the subject entry so that it contains a link to the reply page --%>
<asp:templatecolumn headertext="subject" itemstyle-width=50%>
<template name="itemtemplate" >
<asp:label runat="server" text='<%#"<a href=reply.aspx?postid="+databinder.eval(container, "dataitem.postid")+">"
+databinder.eval(container, "dataitem.subject")+"</a>" %>' id=label2></asp:label>
</template>
</asp:templatecolumn>

<asp:templatecolumn headertext="author name" itemstyle-width=20%>
<template name="itemtemplate">
<asp:label runat="server" text='<%# databinder.eval(container, "dataitem.name") %>' id=label3></asp:label>
</template>
</asp:templatecolumn>


<asp:templatecolumn headertext="replies" itemstyle-width=10%>
<template name="itemtemplate">
<asp:label runat="server" width=10% text='<%# databinder.eval(container, "dataitem.replies") %>' id=label4>
</asp:label>
</template>
</asp:templatecolumn>

<asp:templatecolumn headertext="views" itemstyle-width=10%>
<template name="itemtemplate">
<asp:label runat="server" width=10% text='<%# databinder.eval(container, "dataitem.views") %>' id=label5>
</asp:label>
</template>
</asp:templatecolumn>

<asp:templatecolumn headertext="date of post" itemstyle-width=10%>
<template name="itemtemplate">
<asp:label runat="server" width=10% text='
<%# databinder.eval(container, "dataitem.date").tostring().todatetime().toshortdatestring() %>' id=label6>
</asp:label>

</template>
</asp:templatecolumn>
</property>
</asp:datagrid>
<br>
<br>
<asp:label class=fodark text="<font color=#00000 >post new topic</font>" runat=server />
<br>
<table border="0" width="80%" align="center">
<tr >
<td class="fohead" colspan=2><b>post new topic</b></td>
</tr>
<tr class="folight" >
<td>name :</td>
<td ><asp:textbox text="" id="name" runat="server" />   <font color=#ff0000>*</font></td>
</tr>
<tr class="folight">
<td>e-mail :</td>
<td><asp:textbox text="" id="email" runat="server"/>   <font color=#ff0000>*</font></td>
</tr>
<tr class="folight">
<td> subject:</td>
<td><asp:textbox test="" id="subject" width=200 runat="server"/>   <font color=#ff0000>*</font>
</td></tr>
<tr class="folight">
<td>message :</td>
<td>
<asp:textbox id=message runat="server"
columns="30" rows="15" textmode="multiline"></asp:textbox></td>
</tr>
<tr class=folight>
<td colspan=2>
<asp:button class=fodark id=write onclick=submit_click runat="server" text="submit"></asp:button></td></tr>
</table>
</form>
</center>
<!-- #include file="footer.inc" -->
</body></html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吉首市| 博野县| 宝坻区| 江阴市| 乌恰县| 滦南县| 云阳县| 长垣县| 余干县| 左权县| 安顺市| 酉阳| 镇坪县| 黔南| 北安市| 准格尔旗| 广宗县| 曲周县| 象州县| 方正县| 丰原市| 巴东县| 天津市| 新野县| 望江县| 陇川县| 同心县| 桦甸市| 菏泽市| 绥德县| 临洮县| 遵化市| 文昌市| 汤原县| 怀来县| 莱芜市| 万州区| 万州区| 湛江市| 内乡县| 新余市|