.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson
Eminent IT

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Binding Data list to dataview with out data base

Posted By:Gowthammanju       Posted Date: July 06, 2011    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

This article explains you about Binding of DataList to DataView Without Using Database

Hi Guys,

Just follow this stepsĀ 

For binding images in data list

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            ' bind datalist
            DataListImages.DataSource = GetImages()
        End If
    End Sub
This function used to get images with out data base connection as

This retrives the images from the specific folder of the system

Private Function GetImages() As DataView
        Dim dt As New DataTable
        Dim dr As DataRow
        dt.Columns.Add(New DataColumn("ImageName"))
        dt.Columns.Add(New DataColumn("ImageFile"))
        ' populate the rows
        Dim dir As IO.DirectoryInfo = New DirectoryInfo(Server.MapPath("images"))
        For Each fi As FileInfo In dir.GetFiles("*.jpg")
            dr = dt.NewRow()
            dr(0) = fi.Name.Substring(0, fi.Name.IndexOf("."))
            dr(1) = "images/" & fi.Name
        Dim dv As New DataView(dt)
        Return dv
    End Function

To display items in data boundĀ 

 Protected Sub DataListImages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        If e.Item.ItemType = ListItemType.Header Then
            CType(e.Item.FindControl("ItemsCount"), Label).Text = GetImages.Count.ToString & " items in total"
        End If
    End Sub
In the designing page of aspx use coding as

<%# DataBinder.Eval(Container.DataItem, "ImageName")%>

Hence You find the way

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend