our notes for our youngers

January 1, 2010

developing a site ( part 4 )

Filed under: ASP.NET, developing website — Tags: , , , — sevenlamp @ 2:45 PM

Latest Source Code (1/1/2010 အထိ) http://www.sendspace.com/file/uxkj6h

ကြၽန္ေတာ္ အလြယ္ဆံုးလို႔ ထင္တဲ႔ project ထဲကို About Page ထည့္တဲ႔ အပိုင္းေလးကို အရင္ဆံုး စလုပ္လိုက္ပါတယ္။ project ထဲကို AboutMe.aspx page ေလး ထည့္လိုက္ျပီး။ About မွာ ျပမယ့္ message ေတြအတြက္ entry အပိုင္း က မလုပ္ရေသးေတာ့။ စာသားေတြကို ဒီတိုင္းပဲ Page ထဲကို ထည့္ျပလိုက္ပါတယ္။ comment ေပးတဲ႔ အပိုင္းေလးေရးဖို႔အတြက္၊ Database ထဲမွာ Comments Table သြားေဆာက္လုိက္ပါတယ္။

Column Name Data Type Allow Nulls
CommentID int Unchecked
PostID int Checked
MemberID int Checked
CommentTitle nvarchar(500) Checked
CommentText nvarchar(MAX) Checked
CommentTime datetime Checked
CommentAuthorName nvarchar(50) Checked
CommentAuthorLocation nvarchar(50) Checked

ကြၽန္ေတာ္က DataBase နဲ႔ ခ်ိတ္တဲ႔ ေနရာမွာ objectdatasource ကိုပဲ သံုးမွာ မို႔လို႔ DataSet လည္းေဆာက္ေပးဖို႔လိုပါေသးတယ္။ ျပီးရင္ comment entry အတြက္ textbox ေလးေတြထည့္တယ္။ Validation အတြက္ requirefield validator နဲ႔ email format အတြက္ Regularexpression validator controls ေတြကို ထည့္ထားပါတယ္။ send button ႏွိပ္ရင္ server သြားတဲ႔ အလုပ္ကို updatepanel ထဲမွာ ပဲ ထည့္ေပးလိုက္ပါတယ္။
Comment list ျပန္ျပဖို႔အတြက္ေတာ့ gridview control ကိုပဲ သံုးျပီး object datasource နဲ႔ ခ်ိတ္ျပလိုက္ပါတယ္။ ဒီ page ေလးက ရွင္းပါတယ္။ ကုဒ္လည္း သိပ္မရႈပ္ဘူး။

public partial class AboutMe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "About Page : sevenlamp.co.cc";
        ShowCommentCount();
    }

    private void ShowCommentCount()
    {
        DataSet_CommentTableAdapters.CommentsTableAdapter adp = new DataSet_CommentTableAdapters.CommentsTableAdapter();
        int commentCount = (int)adp.GetCommentCountByPostID(0);
        if (commentCount == 0)
            lblTotalComment.Text = "No Comment";
        else if (commentCount == 1)
            lblTotalComment.Text = commentCount.ToString() + " Comment";
        else
            lblTotalComment.Text = commentCount.ToString() + " Comments";
    }
    protected void SendButton_Click(object sender, EventArgs e)
    {
        ObjectDataSource2.Insert();
    }
    protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        e.InputParameters["CommentTime"] = DateTime.Now;
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ((Label)e.Row.FindControl("lblCommentNo")).Text = "#" + (e.Row.RowIndex+1).ToString();
        }
    }
    protected void ObjectDataSource2_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
    {
        ShowCommentCount();
        GridView1.DataBind();
    }
}

1 Comment »

  1. အစ္ကို….ေက်းဇူးပါပဲ။ ။ ကြ်န္ေတာ္က web developer ဴဖစ္ခ်င္တဲ့သူပါ….ဟိဟိဟိ။ ။ အခု asp.net with C# သင္တန္းတက္ေနတာပါ။ ။ အစ္ကိုရဲ့ C# language နဲ့ေရးထားတဲ့ .net develop အကူညီေဳကာင့္လံုး၀နားလည္ေစတာဗ်ာ။ ။ ပညာနဲ့ အခြင့္လမ္းေတြ ဒီထက္ပိုဴပီး
    တိုးတက္သာယာပါေစဗ်ာ။ ။

    Comment by Win Thu — November 17, 2010 @ 3:38 AM


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: