C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET GridView »

Binding Images to Gridview


Posted Date: 17 Aug 2009    Resource Type: Code Snippets    Category: ASP.NET GridView
Author: NeetuMember Level: Diamond    
Rating: 1 out of 5Points: 6



Binding Images to Gridview


In this program gridview consist of the different different pictures in the columns.

Default.aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" Runat="server"
AutoGenerateColumns="False"
BorderWidth="1px" BackColor="White" CellPadding="3" BorderStyle="None"
BorderColor="#CCCCCC" Font-Names="Arial">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<PagerStyle ForeColor="#000066" HorizontalAlign="Left"
BackColor="White"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True"
BackColor="#006699"></HeaderStyle>
<Columns>
<asp:BoundField HeaderText="Picutre ID" DataField="PictureID">
<ItemStyle HorizontalAlign="Center"
VerticalAlign="Middle"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Title" DataField="Title"></asp:BoundField>
<asp:BoundField HeaderText="Date Added" DataField="DateAdded"
DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:ImageField DataImageUrlField="PictureURL"></asp:ImageField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True"
BackColor="#669999"></SelectedRowStyle>
<RowStyle ForeColor="#000066"></RowStyle>
</asp:GridView>

</div>
</form>
</body>
</html>




Code for default.aspx.vb

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dt As New System.Data.DataTable()

If Not Page.IsPostBack Then

Dim selecttext As New ButtonField
selecttext.ButtonType = ButtonType.Button
selecttext.CommandName = "SELECT"
selecttext.Text = "Select"
selecttext.HeaderText = "Select"
'selecttext.
' define the table's schema

dt.Columns.Add(New System.Data.DataColumn("PictureID", GetType(Integer)))
dt.Columns.Add(New System.Data.DataColumn("PictureURL", GetType(String)))
dt.Columns.Add(New System.Data.DataColumn("Title", GetType(String)))
dt.Columns.Add(New System.Data.DataColumn("DateAdded", GetType(DateTime)))
' Create the four records
Dim dr As System.Data.DataRow = dt.NewRow()
dr("PictureID") = 1

dr("PictureURL") = ResolveUrl("~/Images/img03.gif")
dr("Title") = "hello"
dr("DateAdded") = New DateTime(2005, 1, 15)
dt.Rows.Add(dr)
dr = dt.NewRow()

dr("PictureID") = 1
dr("PictureURL") = ResolveUrl("~/Images/outbound.ico")
dr("Title") = "helo"
dr("DateAdded") = New DateTime(2005, 1, 21)
dt.Rows.Add(dr)
dr = dt.NewRow()

dr("PictureID") = 1
dr("PictureURL") = _
ResolveUrl("~/Images/img03.gif")
dr("Title") = "hello"
dr("DateAdded") = New DateTime(2005, 2, 1)
dt.Rows.Add(dr)
dr = dt.NewRow()

dr("PictureID") = 1
dr("PictureURL") = ResolveUrl("~/Images/outbound.ico")
dr("Title") = "hhh"
dr("DateAdded") = New DateTime(2005, 2, 18)
dt.Rows.Add(dr)
GridView1.Columns.Add(selecttext)
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
End Class


regards
Neetu

Attachments

  • Dealing with gridview and datatable (31411-1747-Gridwithpic Yes.rar)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Gridview  .  Binding pictures in column of gridview  .  Bind Images  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Binding Dropdownlist inside a GridView when a button is clicked:
    Previous Resource: Custom Control for a Bound Field Containing Div Tag.
    Return to Discussion Resource Index
    Post New Resource
    Category: ASP.NET GridView


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use