• 随便写写之一:GridView简单使用


     

        微软对外公布11月底vs2008出正式版,开发用的IDE更新的很快,使我有些力不从心。Framework 2.0还没掌握,3.03.5又出来了,哎。。。前几天看了一篇blog文章,说技术够用就可以,能满足自己开发的需要。我非常同意这个观点。若是追新,活到老也学不完,但只学自己用到的,自己感兴趣的。呵。。,有时够用主义原则也不错,呵。。,好了,现在开始说说vs2005的简单使用吧,其实网上对vs2005的使用文献baidu一下,一大堆,写blog,一是分享心得,二是当做日记本,记录下。

       好了,开始了,这篇简单说下在vs2005中的 gridview自定义分页的使用.这里只贴出部分代码:
         
    1.在页面中拖放gridview控件,设置AllowPaging=true,激活OnPageIndexChanging事件

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                            BorderStyle
    ="None" BorderWidth="0px" OnPageIndexChanging="GridView1_PageIndexChanging"
                            ShowHeader
    ="False" Width="442px">
                            
    <Columns>
                                
    <asp:TemplateField>
                                    
    <ItemTemplate>
                                        
    <itemtemplate>
                                                                  
                                                                    
    <a href="NewsContent.aspx?newsId=<%#Eval("NewsID") %>" target="_blank">
                                                                        
    <%#GetCutTitle(Eval ( "NewsTitle" ).ToString())%>
                                                                    
    </a>
                                                                
    </itemtemplate>
                                    
    </ItemTemplate>
                                
    </asp:TemplateField>
                            
    </Columns>
                            
    <PagerTemplate>
                                当前
                                
    <asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>/<asp:Label
                                    ID
    ="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
                                
    <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="First" CommandName="Page"
                                    Visible
    ="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
                                
    <asp:LinkButton ID="LinkButton2" runat="server" CommandArgument="Prev" CommandName="Page"
                                    Visible
    ="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
                                
    <asp:LinkButton ID="LinkButton3" runat="server" CommandArgument="Next" CommandName="Page"
                                    Visible
    ="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton><asp:LinkButton
                                        ID
    ="LinkButton4" runat="server" CommandArgument="Last" CommandName="Page" Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">末页</asp:LinkButton>
                                转
    <asp:TextBox ID="tbPage" runat="server" Width="30px"></asp:TextBox>
                                
    <asp:Button ID="btnSkipPage" runat="server" OnClick="btnSkipPage_Click" Text="Go" />
                            
    </PagerTemplate>
                        
    </asp:GridView>

     

    2.在输入页码,点击go按钮转到相应页面,go按钮事件实现如下:
     

     protected void btnSkipPage_Click ( object sender, EventArgs e )
            
    {
            GridViewRow item 
    = this.GridView1.BottomPagerRow;
            TextBox currentPage 
    = ( TextBox )( item.Cells[0].FindControl ( "tbPage" ) );
            
    //Common.CheckNum是检证参数是否为数字,这个方法请大家用正则表达式自己写吧
            if ( !string.IsNullOrEmpty ( currentPage.Text ) && Common.CheckNum ( currentPage.Text ) )
                
    {
                
    this.GridView1.PageIndex = Convert.ToInt32(currentPage.Text.Trim())-1;
                }

            
    else
                
    {
                
    this.GridView1.PageIndex = 0;
                }

            DataBinder ( );

            }

     

    3.运用Ajax实现异步刷新(在以后的文章专门介绍Ajax简单使用)

    在前台页面拖放ScriptManager控件,前提是你已经安装Asp.Net Ajax 1.0组件,若没有安装的话,请到微软官网上下载并安装.

    然后再拖放UpdatePanel控件,将gridview控件拖放到UpdatePanel控件ContentTemplate模版中,一切就ok.

    当然要运行Ajax,还得在web.config中进行配置,参照我以前的文章:
     

    asp.net ajax 1.0 出现"sys"未定义解决方法


     

    下面是源代码文件:

    /Files/kevinlzf/GridViewDemo.rar
    在线编辑器不支持中文文件名

  • 相关阅读:
    php sendmail 安装配置
    linux 创建git 仓库
    laravel 项目 配置 nginx
    lnmp 搭建后,nginx下php文件404但是html文件正常访问【已解决】
    为什么 ++[[]][+[]]+[+[]] = 10 ?
    JS移动客户端--触屏滑动事件
    前端开发Vue框架--(一)
    Django数据库优化及事务
    Django聚合查询、分组查询、F与Q查询
    django篇--->十(auth模块)
  • 原文地址:https://www.cnblogs.com/kevinlzf/p/952949.html
Copyright © 2020-2023  润新知