meiwn

导航

FormView中的PagerTemplate的使用

<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
  
<title>GridView DetailsView Master-Details (with Editing)</title>
</head>
<script runat="server">





    
protected void FormView1_DataBound(object sender, EventArgs e)
    
{
        
//注意是在BottomPagerRow中,
     
        
if ((FormView1.PageIndex + 1== FormView1.PageCount)
        
{

          ((Button)FormView1.BottomPagerRow.FindControl(
"Last")).Enabled = false;
          ((Button)FormView1.BottomPagerRow.FindControl(
"Next")).Enabled = false;

        }

        
if (FormView1.PageIndex == 0)
        
{
            ((Button)FormView1.BottomPagerRow.FindControl(
"First")).Enabled = false;
            ((Button)FormView1.BottomPagerRow.FindControl(
"Prev")).Enabled = false;
        }

    }



</script>
<body>
  
<form id="form1" runat="server">
    
<br />
      
&nbsp;<asp:FormView ID="FormView1" runat="server" DataKeyNames="au_id" DataSourceID="SqlDataSource5" AllowPaging="True" OnDataBound="FormView1_DataBound" >

          
<ItemTemplate>
              au_id:
              
<asp:Label ID="au_idLabel" runat="server" Text='<%# Eval("au_id") %>'></asp:Label><br />
              
<br />
          
</ItemTemplate>
          
<PagerTemplate>
              
&nbsp;
              
<asp:Button ID="First" runat="server" Text="First" CommandArgument="First" CommandName="Page" />
              
<asp:Button ID="Prev" runat="server" CommandArgument="Prev" CommandName="Page"
                  Text
="Prev" />
              
<asp:Button ID="Next" runat="server" Text="Next" CommandName="Page" CommandArgument="Next" />&nbsp;
              
<asp:Button ID="Last" runat="server" Text="Last" CommandArgument="Last" CommandName="Page" />
          
</PagerTemplate>
      
</asp:FormView>
 

      
<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:Pubs %>"
          SelectCommand
="SELECT * FROM [authors]"></asp:SqlDataSource>
      
&nbsp; &nbsp;&nbsp;
      
  
</form>
</body>
</html>

posted on 2006-09-16 12:09  努力学习.NET  阅读(1136)  评论(0编辑  收藏  举报