Forum.aspx Forum Homepage

Source: Internet
Author: User
Tags date datetime eval include tostring
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"%>
<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 is 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 strconn=@ "provider=microsoft.jet.oledb.4.0;D ata 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 would be shown a
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 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 was called when the ' DataGrid is Paged (i.e.???
public void Datagrid_updt (Object sender, DataGridPageChangedEventArgs e)
{
Call the "method" to Databind
Binding ();
}
This are 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 would be used to call the Postmessage.aspx page.
Since It'll be is a query we have to encode the query into UTF8 format.
So I get all of 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 which 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 the" Required Fields before posting!<br> ";
}
}
</script>
<link href= "Mystyle.css" Type=text/css rel=stylesheet><body topmargin= "0" leftmargin= "0" rightmargin= "0" marginwidth= "0" marginheight= "0" >
<!--#Include file= "Header.inc"-->
<center>
<asp:label id= "errmess" text= "style=" COLOR: #ff0000 "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. It very interesting how much can play with it--%>
<asp:datagrid id=datagrid1 runat= "server" forecolor= "BLACK"
Pagerstyle-mode= "NumericPages"
Onpageindexchanged= "DATAGRID_UPDT" pagesize= "" 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 this 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 >
&LT;TD class= "Fohead" Colspan=2><b>post New topic</b></td>
</tr>
<tr class= "Folight" >
<td>name:</td>
&LT;TD ><asp:textbox text= "" id= "name" runat= "Server"/> <font #ff0000 >*</font></td>
</tr>
<tr class= "Folight" >
<td>e-mail:</td>
<td><asp:textbox text= "" id= "email" runat= "server"/> <font #ff0000 color= >
</tr>
<tr class= "Folight" >
<td> subject:</td>
<td><asp:textbox test= "" id= "subject" width=200 runat= "server"/> <font #ff0000 color= >
</td></tr>
<tr class= "Folight" >
<td>message:</td>
<td>
<asp:textbox id=message runat= "Server"
columns= "rows=" textmode= "MultiLine" ></asp:TextBox></td>
</tr>
<tr class=folight>
&LT;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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.