Thursday, 8 September 2011

IMAGE DSPALY IN GRIDVIEW


Asp.net design:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Girdviewimagesdisplay.aspx.cs" Inherits="Girdviewimagesdisplay" %>

<!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" >
        <Columns >
        <asp:TemplateField HeaderText ="PRODUCT ID" ControlStyle-Font-Bold ="true " HeaderStyle-ForeColor ="Blue"  >
        <ItemTemplate >
        <asp:Label ID="lblpid" runat ="server" Text ='<%#Eval("PID") %>'></asp:Label>
        </ItemTemplate>
       
        </asp:TemplateField>
        <asp:TemplateField HeaderText ="PRODUCT NAME" ControlStyle-Font-Bold ="true " HeaderStyle-ForeColor ="Blue" >
        <ItemTemplate >
        <asp:Label ID="lblpname" runat ="server" Text ='<%#Eval("PNAME") %>'></asp:Label>
       
        </ItemTemplate>
        <EditItemTemplate >
        <asp:TextBox ID="txtpname" runat ="server" ></asp:TextBox>
       
       
        </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText ="DESCRPTION" ControlStyle-Font-Bold ="true " HeaderStyle-ForeColor ="Blue" >
        <ItemTemplate >
        <asp:Label ID="lbldesc" runat ="server" Text ='<%#Eval("DESCP") %>'></asp:Label>
       
        </ItemTemplate>
        <EditItemTemplate >
        <asp:TextBox ID="txtdesc" runat ="server" ></asp:TextBox>
       
       
        </EditItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText ="IMAGE" ControlStyle-Font-Bold ="true " HeaderStyle-ForeColor ="Blue" >
        <ItemTemplate >
       <asp:Image ImageUrl ='<%#Eval("IMAGENAME ")%>' runat ="server" Width ="90px" />
       
        </ItemTemplate>
        <EditItemTemplate >
        <asp:TextBox ID="txtimg" runat ="server" ></asp:TextBox>
       
       
        </EditItemTemplate>
        </asp:TemplateField>
        </Columns>
        </asp:GridView>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
   
    </div>
    </form>
</body>
</html>


c# code behind:



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


public partial class Girdviewimagesdisplay : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        imgdispalyDataContext ds = new imgdispalyDataContext();
        var product = from a in ds.PRODETs select a;
        GridView1.DataSource = product;
        GridView1.DataBind();
     
    }
}



No comments:

Post a Comment