<%@ 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>
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.