Asp.net FormView with Xml And Paging

if you are a classic asp developer then you know how painfull it is to connect with a XML file, Read it and then Page Through it.

Thanks to Asp.net's xml & data NameSpaces. in just a couple of lines you can connect to a xml file (remote or local file) and then actualy page through it.

Code is Below:

CODE BEHIND ----------

The Xml File--


 
    Saqib Khan
    26
    USA
 

 
    Sabir Khan
    31
    USA
 

 
    Adil Khan
    13
    USA
 

 
 


The Aspx File ---

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="formviewxml.aspx.vb" Inherits="Tests_formviewxml" %>

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

http://www.w3.org/1999/xhtml" >

    Untitled Page


   
   


   
   
       
           Name: <%#Eval("Name")%>
       
       
           Age: <%#Eval("Age")%>
       
        
           Country: <%#Eval("location")%>
       
       
           
       
   

   

   

   


Code Behind File ---

Imports System.Xml
Imports System.Data

Partial Class Tests_formviewxml
    Inherits System.Web.UI.Page

 

    Private Sub xmlDate()

        Dim dt As New DataSet
        Dim xml As XmlTextReader
        Dim path As String

        path = Page.ResolveUrl("~") & "tests/xmlformview.xml"
        xml = New XmlTextReader(path)

        dt.ReadXml(xml)

        xmlform.DataSource = dt
        xmlform.DataBind()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.Header.Title = "Asp.Net FormView With Xml & Paging"
        Call Me.xmlDate()

        If Not Page.IsPostBack Then
            Me.CounterMsg(CType(xmlform.FindControl("counter"), Label), xmlform.PageCount, xmlform.PageIndex)
        End If

    End Sub

 


    Protected Sub xmlform_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles xmlform.PageIndexChanging
        xmlform.PageIndex = e.NewPageIndex
        Me.xmlDate()
        Me.CounterMsg(CType(xmlform.FindControl("counter"), Label), xmlform.PageCount, xmlform.PageIndex)
    End Sub

    Private Sub CounterMsg(ByVal ctrl As Label, ByVal pageCount As Integer, ByVal currentpage As Integer)
        If Not ctrl Is Nothing Then
            ctrl.Text = "(Viewing Page " & currentpage + 1 & " of " & pageCount & ")"
        End If
    End Sub


End Class
 

Posted by:

Comments History


by: on
if you learning how to create a FormView Tutorial, then please visit below: http://www.knowlegezone.com/documents/33/Aspnet-FormView-Tutorial----ItemTemplate/
 
by: on
good
 

Name :  

Email :  

Comment Below