Chinaunix首页 | 论坛 | 博客
  • 博客访问: 143894
  • 博文数量: 48
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 630
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-03 20:57
文章分类

全部博文(48)

文章存档

2010年(4)

2009年(23)

2008年(21)

我的朋友

分类:

2008-07-31 08:52:48

实例说明

留言板是目前网络比较流行的、方便的、快捷的一种用来保存留言的网络工具。用户可以通过留言板为网站管理人员留言,也可以作为用户与管理员交流的通信工具。留言板通常应用在企业门户网站、电子商务销售平台网等网站。本实例开发的留言板如图所示。

图  留言板的信息展开

技术要点

DynamicPopulate控件提供了一种动态效果,能通过WebService或访问服务器端代码获取一段HTML文本,并替换掉目标控件上原来的内容。DynamicPopulate控件的主要属性及说明如表所示,

表 DynamicPopulate控件的属性及说明

属性

说明

TargetControlID

将具备“动态呈现”的Panel控件的值

ClearContentsDuringUpdate

当更新时,是否清除目标元素中的既有HTML内容。若没有指定,将会自动 清除 HTML内容,默认值为true

SerivcePath

将要调用的Web服务的URL。如果调用一个页面方法,就不用设置些属性

SerivceMethod

Web服务方法或页面方法的名称

PopulateTriggerControlID

一个选择的属性,用来指定某个控件被单击时,要触发目标元素进行动态呈现

UpdatingCssClass

在异步调用(Asynchronous Call)时,欲套用到目标元素的CSS类属性

CustomScript

替换原本将要调用的Web服务方法或页面方法,改调用指定的脚本(Script),它必须计算机为一个字符串值

ContextKey

将传递给Web方法的任意字符串值。比方说,动态呈现欲显示一个绑定到资料的Repeater, 那么所传入的字符串值可以是目前该行数据的ID值

 

实现过程

(1)新建一个AJAX网站,命名为07,默认窗体为Default.aspx。

(2)在Default.aspx窗体中主要添加一个ScriptManager控件、一个UpdatePanel控件和一个GridView控件,分别用于管理页面中的AJAX控件、实现局部更新、显示留言板信息。

(3)对GridView控件进行编辑列,添加一个TemplateField项。

(4)编辑GridView模板,在模板中设计代码如下:


                   
              
                      
                               

                                 
                                    
                                                留言标题:
                                            
                                                <%# Eval("title") %>
                                            
                                        

                                        
                                            
                                                留言内容:
                                            
                                                <%# Eval("message") %>
                                            
                                        

                                        
                                            
                                            
                                            
                                                
                                                    

         
                 我要留言 '>我要回复
         展开>> 
                  
                                                    

                                                    
          
           
                                                            
                                                        
                                                    

                                                    
          
                  ServiceMethod="GetReplyByMessage" ContextKey='<%# Eval("ID") %>' ClearContentsDuringUpdate="true"
                        PopulateTriggerControlID="hlnkShow" TargetControlID="plReturn">
        
                                                        
                                                    

                                                
  
           
              

                                            
                                        
                                        
                                            
                                            
                                            
                                                
                                                    
                                               
                                                   留言人联系方式:
                                              
                                              '>
                                                     <%# Eval("Email") %>
                                                  
                                              
                                            时间:
                                        
                                   [<%# Eval("CreateDate") %>]
                               
                       
                   
                 
           
        /table>
   

(5)创建一个Web服务,命名为Return.asmx。在WEB服务中创建GetReplyByMessage方法来实现留言板中的信息展开。代码如下:

");
        }
        return returnHtml.ToString();
    }
    [WebMethod]
    public string GetReplyByMessage(string contextKey)
    {
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Ex18_07.mdb"));
        OleDbDataAdapter da = new OleDbDataAdapter("select * from tb_reply  where messageID = " + contextKey + " Order by CreateDate DESC", conn);
        DataSet ds = new DataSet();
        da.Fill(ds);

        if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
        {
            return string.Empty;
        }
        StringBuilder returnHtml = new StringBuilder();
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            returnHtml.Append("
回复" + row["CreateDate"]);
            returnHtml.Append("
");
            returnHtml.Append(row["Reply"]);
            returnHtml.Append("

(6)在Default.aspx.cs文件获取数据库中的留言信息,实现代码如下:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Ex18_07.mdb"));
            OleDbDataAdapter da = new OleDbDataAdapter("select * from tb_Message  Order by CreateDate DESC", conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
    }

阅读(5902) | 评论(45) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-12-27 17:14:03

[url=http://www.fivefingerusa.com]vibram five fingers[/url] [url=http://www.fivefingerusa.com]five finger shoes[/url] [url=http://www.fivefingerusa.com]vibram shoes[/url] [url=http://www.fivefingerusa.com]five finger[/url] [url=http://www.mbtinshop.com]mbt shoes[/url] [url=http://www.mbtinshop.com]wholesale mbt shoes[/url] [url=http://www.mbtinshop.com]cheap mbt shoes[/url] [url=http://www.mbtinshop.com]discount mbt shoes[/url] [url=http://www.mbtinshop.com]mbt[/url] [url=http://www.o

chinaunix网友2010-08-17 20:06:37

北京到重庆特价机票.北京到成都特价机票.北京到广州特价机票.北京到深圳特价机票.北京到乌鲁木齐特价机票.北京到西安特价机票.北京到昆明特价机票.北京到桂林特价机票.北京到厦门特价机票.北京到上海特价机票.北京到贵阳特价机票.北京到温州特价机票.北京到福州特价机票.北京到海口特价机票.北京到银川特价机票.北京到南宁特价机票.北京到西宁特价机票.北京到宁波特价机票.北京到长沙特价机票.北京到兰州特价机票.北京到南昌特价机票.北京到武汉特价机票.北京到杭州特价机票.北京到珠海特价机票.北京到汕头特价机票.北京到三亚特价机票.特价机票.北京特价机票.机票..

chinaunix网友2010-05-07 08:30:12

WATCH BOXES http://www.bigbigwatch.com/WATCH-BOXES-Watches-91.html MONT BLANC PEN http://www.bigbigwatch.com/MONT-BLANC-PEN-Watches-120.html ALAIN SILBERSTEIN http://www.bigbigwatch.com/ALAIN-SILBERSTEIN-Watches-26.html ANONIMO http://www.bigbigwatch.com/ANONIMO-Watches-27.html A.LANGE & SOHNE http://www.bigbigwatch.com/A.LANGE-and-SOHNE-Watches-28.html AUDEMARS PIGUET http://www.bigbigwatch.com/AUDEMARS-PIGUET-Watches-29.html BAUME & MERCIER http://www.bigbigwatc

chinaunix网友2010-04-09 10:51:56

Air jordan XII: http://www.brandclothingstore.com/wholesale/Air-Jordan-XII-696_p1.html bape shorts: http://www.brandclothingstore.com/wholesale/Bape-Shorts-802_p1.html Air jrodan XIII: http://www.brandclothingstore.com/wholesale/Air-Jordan-XIII-697_p1.html Air jordan XXIV: http://www.brandclothingstore.com/wholesale/Air-Jordan-XXIV-705_p1.html Bape clothing: http://www.brandclothingstore.com/wholesale/Bape-Clothing-602_p1.html Air jordan XXV: http://www.brandclothingstore.com/wholesal

chinaunix网友2010-04-09 10:51:28

lacoste clothing: http://www.coogiwarehouse.com/wholesale/Lacoste-Clothing-511_p1.html prada clothing: http://www.coogiwarehouse.com/wholesale/Prada-Clothing-512_p1.html baby phat clothing: http://www.coogiwarehouse.com/wholesale/Baby-Phat-467_p1.html affliction clothing: http://www.coogiwarehouse.com/wholesale/Affliction-465_p1.html laguna Beach clothing: http://www.coogiwarehouse.com/wholesale/Laguna-Beach-Clothing-471_p1.html G-star clothing: http://www.coogiwarehouse.com/wholesale