Saturday, August 31, 2013

Dynamic Image Gallery and Slide Show with the help of C# Asp.Net and SQL Server

Hello friends, Today I would like tell to you that , how can we built  dynamic Image Gallery and slide show with the help of C# asp.net, SQL Server and Jquery. I will be explain all development step by step and you can also download this demo project from here.

Step 1: First of all  i will be design database.

1.CREATE TABLE [dbo].[Gallary](
 [Id] [int] IDENTITY(1,1) NOT NULL,
 [galleryid] [int] NULL,
 [description] [nvarchar](250) NULL,
 [thumbimage] [nvarchar](50) NULL,
 [gallimage] [nvarchar](50) NULL,
 [cretedate] [datetime] NULL,
 CONSTRAINT [PK_Gallary] PRIMARY KEY CLUSTERED
(
 [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


2. CREATE TABLE [dbo].[Gallarydesc](
 [id] [int] IDENTITY(1,1) NOT NULL,
 [gallaryname] [nvarchar](50) NULL,
 [creatdate] [datetime] NULL,
 [status] [bit] NULL,
 [thumbnails] [nvarchar](150) NULL,
 CONSTRAINT [PK_Gallarydesc] PRIMARY KEY CLUSTERED
(
 [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


3. Store-procedure

Create PROCEDURE [dbo].[usp_gallary]

@Action nvarchar(50)='',
@name nvarchar(50)='',
@id int=0,
@status bit=0,
@image1 nvarchar(100)='',
@image2 nvarchar(100)='',
@description nvarchar(150)='',
@title nvarchar(100)='',
@path nvarchar(500)=''
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here
    if(@Action='getgalleryname')
    begin
 SELECT id,gallaryname,status,'data_banner/thumbnails/'+thumbnails as image from Gallarydesc
 end
 if(@Action='insertgall')
 begin
 if exists(select * from Gallarydesc where gallaryname=@name)
 select'This Album name already exists'as msg
 else
 insert into Gallarydesc (gallaryname,status,creatdate) values(@name,'1',GETDATE())
 select'Gallary add to database successfully!'as msg
 end
 if(@Action='updategallary')
 begin
 update Gallarydesc set gallaryname=@name,thumbnails=@image1 where Id=@id
  select'Gallary update to database successfully!'as msg
 end
 if(@Action='getgalleryforedit')
 begin
 select gdesc.id,gdesc.description,gdesc.description,'data_banner/images/'+gdesc.thumbimage as image,gal.gallaryname,'data_banner/thumbnails/'+gal.thumbnails as image2 from dbo.Gallary as gdesc inner join dbo.Gallarydesc as gal on gdesc.id=gal.id
 end
 if(@Action='getallvisalbum')
 begin
 select * from dbo.Gallarydesc where status='1'
 end
 if(@Action='insertgaldesc')
 begin
 insert into dbo.Gallary (galleryid,description,thumbimage,cretedate) values(@id,@description,@image1,GETDATE())
 select'Image add to database successfully!'as msg
 end
 if(@Action='updategallrydec')
 begin
 update dbo.Gallary set description=@description,thumbimage=@image1 where ID=@id
 end


END

Step 2: Managegallery.aspx(For enter image in database)

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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!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 id="Head1" runat="server">
    <title></title><style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;


} .modalPopup
                 {
           
                 text-align:left;           
                 border-width: 0px;
                 padding: 0px;
               margin:0;
               box-shadow:none;
               margin-top:-15px;
              background:#fff;
                 }
            
        .PanelCSS 
        {     text-align:left
            visibility:hidden;
            background:#fff;
           padding:10px;
           width:150px;
            border:1px solid #000;
            } 
  
                 </style>
</head>
<body>
    <form id="form1" runat="server"><fieldset><legend>Manage Gallary</legend>
    <div>
<asp:toolkitscriptmanager ID="Toolkitscriptmanager1" runat="server"></asp:toolkitscriptmanager>
    <table width="950px"><tr><td><asp:GridView ID="gvDetails"  runat="server"
AutoGenerateColumns="False" CssClass="Gridview"
ShowFooter="True"
onrowcancelingedit="gvDetails_RowCancelingEdit"
onrowdeleting="gvDetails_RowDeleting" onrowediting="gvDetails_RowEditing"
onrowupdating="gvDetails_RowUpdating"
onrowcommand="gvDetails_RowCommand" EnableModelValidation="True"
                     onrowdatabound="gvDetails_RowDataBound" Width="750px">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="Images/update.jpg" ToolTip="Update" Height="20px" Width="20px" />
<asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="Images/Cancel.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="Images/Edit.jpg" ToolTip="Edit" Height="20px" Width="20px" />
<asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="Images/AddNewitem.jpg" CommandName="AddNew" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
</FooterTemplate>
</asp:TemplateField>


       
        <asp:TemplateField  HeaderText=" Name"><ItemTemplate><asp:label ID="lblcomname" runat="server"  Text='<%#Eval("gallaryname") %>'></asp:label></ItemTemplate>
        <EditItemTemplate><asp:Label ID="lbdeptid" runat="server" Text='<%#Eval("id") %>' Visible="false"></asp:Label> <asp:Label ID="lblid" runat="server" Text='<%#Eval("ID") %>' Visible="false"></asp:Label><asp:TextBox ID="txtcom" runat="server"  Text='<%#Eval("gallaryname") %>'></asp:TextBox><asp:Label ID="img3" runat="server" Text='<%#Eval("image") %>' Visible="false"></asp:Label></EditItemTemplate>
           
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Left" />
            <FooterTemplate><asp:TextBox ID="txtftrusrname" runat="server"></asp:TextBox>
</FooterTemplate>
            </asp:TemplateField><asp:TemplateField  HeaderText="Upload File">
            <ItemTemplate> <asp:Label ID="questionview" runat="server" Text="View"></asp:Label>
                       
                       <asp:HoverMenuExtender ID="hme2" runat="Server" 
    TargetControlID="questionview"
    PopupControlID="panel1"
    HoverCssClass="popupHover"
    PopupPosition="top"
   
    OffsetX="0"
    OffsetY="0"
    PopDelay="50" /><asp:Panel ID="panel1" runat="server" CssClass="PanelCSS"><asp:Image ID="imgg" runat="server" ImageUrl='<%#Eval("image") %>' Width="150px" Height="110px" />                    </asp:Panel></ItemTemplate>
        <EditItemTemplate><asp:Label ID="img2" runat="server" Text='<%#Eval("image") %>' Visible="false"></asp:Label>
        <asp:FileUpload ID="fileupload2" runat="server" />
        </EditItemTemplate>
           
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Left" />
            <FooterTemplate><asp:FileUpload ID="fileupload1" runat="server" />
</FooterTemplate>
            </asp:TemplateField>
</Columns>
    <HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White" />
</asp:GridView></td></tr></table>
<table width="950px"><tr><td><asp:GridView ID="GridView1"  runat="server"
AutoGenerateColumns="False" CssClass="Gridview"
ShowFooter="True"
 EnableModelValidation="True"
                     Width="750px"
        onpageindexchanging="GridView1_PageIndexChanging"
        onrowcancelingedit="GridView1_RowCancelingEdit"
        onrowcommand="GridView1_RowCommand" onrowdeleted="GridView1_RowDeleted"
        onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
        onrowupdating="GridView1_RowUpdating"
        onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="Images/update.jpg" ToolTip="Update" Height="20px" Width="20px" />
<asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="Images/Cancel.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="Images/Edit.jpg" ToolTip="Edit" Height="20px" Width="20px" />
<asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="Images/AddNewitem.jpg" CommandName="AddNew" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
</FooterTemplate>
</asp:TemplateField>


       
        <asp:TemplateField  HeaderText=" Gallary Name"><ItemTemplate><asp:label ID="lblcomname1" runat="server"  Text='<%#Eval("gallaryname") %>'></asp:label></ItemTemplate>
        <EditItemTemplate><asp:Label ID="lbdeptid" runat="server" Text='<%#Eval("id") %>' Visible="false"></asp:Label> <asp:Label ID="lblid" runat="server" Text='<%#Eval("ID") %>' Visible="false"></asp:Label><asp:TextBox ID="txtcom1" runat="server"  Text='<%#Eval("gallaryname") %>'></asp:TextBox><asp:Label ID="img3" runat="server" Visible="false" Text='<%#Eval("image")%>'></asp:Label></EditItemTemplate>
           
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Left" />
            <FooterTemplate><asp:DropDownList ID="ddlgal" runat="server"></asp:DropDownList>
</FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField  HeaderText=" Description"><ItemTemplate><asp:label ID="lblcomname" runat="server"  Text='<%#Eval("description") %>'></asp:label></ItemTemplate>
        <EditItemTemplate><asp:Label ID="img5" runat="server" Text='<%#Eval("image") %>' Visible="false"></asp:Label><asp:TextBox ID="txtcom" runat="server"  Text='<%#Eval("description") %>'></asp:TextBox></EditItemTemplate>
           
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Left" />
            <FooterTemplate><asp:TextBox ID="txtftrusrname" runat="server"></asp:TextBox>
</FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField  HeaderText="Upload File"><ItemTemplate> <asp:Label ID="questionview" runat="server" Text="View"></asp:Label>
                       
                       <asp:HoverMenuExtender ID="hme2" runat="Server" 
    TargetControlID="questionview"
    PopupControlID="panel1"
    HoverCssClass="popupHover"
    PopupPosition="top"
   
    OffsetX="0"
    OffsetY="0"
    PopDelay="50" /><asp:Panel ID="panel1" runat="server" CssClass="PanelCSS"><asp:Image ID="imgg" runat="server" ImageUrl='<%#Eval("image") %>' Width="150px" Height="110px" />                    </asp:Panel></ItemTemplate>
        <EditItemTemplate>
        <asp:FileUpload ID="fileupload2" runat="server" />
        </EditItemTemplate>
           
            <HeaderStyle HorizontalAlign="Left" />
            <ItemStyle HorizontalAlign="Left" />
            <FooterTemplate><asp:FileUpload ID="fileupload1" runat="server" />
</FooterTemplate>
            </asp:TemplateField>
</Columns>
    <HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White" />
</asp:GridView></td></tr></table>
    </div></fieldset>
    </form>
</body>
</html>



Step 3: managegallery.cs

using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.IO;
using AjaxControlToolkit;
using System.Text;

public partial class managegallery : System.Web.UI.Page
{
    Hashtable hst = new Hashtable();
    DataTable dt = new DataTable();
    DataSet ds = new DataSet();
    ConnectionString kpcon = new ConnectionString();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindgaall();
            bindgallery();
        }

    }
  
    {
        hst.Clear();
        dt.Clear();
        ds.Clear();
        hst.Add("Action", "getgalleryname");

        // hst.Add("subjectid ", ddlsub.SelectedValue.ToString());
        // hst.Add("productid ", ddlpro.SelectedValue.ToString());
        ds = kpcon.GetDataSet("[usp_gallary]", hst);
        if (ds.Tables[0].Rows.Count > 0)
        {
            gvDetails.DataSource = ds;
            gvDetails.DataBind();


        }
        else
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            gvDetails.DataSource = ds;
            gvDetails.DataBind();
            int columncount = gvDetails.Rows[0].Cells.Count;
            gvDetails.Rows[0].Cells.Clear();
            gvDetails.Rows[0].Cells.Add(new TableCell());
            gvDetails.Rows[0].Cells[0].ColumnSpan = columncount;
            gvDetails.Rows[0].Cells[0].Text = "No Records Found";

        }
    }
    protected void gvDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvDetails.EditIndex = -1;
        bindgallery();

    }
    protected void gvDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("AddNew"))
        {
            TextBox txtUsrname = (TextBox)gvDetails.FooterRow.FindControl("txtftrusrname");
          
            hst.Clear();
            dt.Clear();
            ds.Clear();
            hst.Add("Action", "insertgall");
        
            hst.Add("Name ", txtUsrname.Text.ToString());
          

            string Msg = string.Empty;
            Msg = Convert.ToString(kpcon.ExecuteScalar("[usp_gallary]", hst));
            if (Msg == "This Album name already exists")
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('This Album name already exists');", true);

            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Gallary add to database successfully!');", true);

            }
            bindgallery();
        }

    }
    protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }
    protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }
    protected void gvDetails_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvDetails.EditIndex = e.NewEditIndex;
        bindgallery();
    }
    protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label img3 = (Label)gvDetails.Rows[e.RowIndex].FindControl("img3");
       
        string FileName = string.Empty, sValidImage = string.Empty, sExe = string.Empty, sSavePath = string.Empty;
        string str="";
        TextBox strgal = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtcom");
        FileUpload fileupload1 = (FileUpload)gvDetails.Rows[e.RowIndex].FindControl("fileupload2");
        if (fileupload1.HasFile)
        {
            FileName = DateTime.Now.Day + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + "_" + DateTime.Now.Ticks;
            sValidImage = ".JPG,.JPEG,.BITMAP,.GIF,.BMP";
            sExe = System.IO.Path.GetExtension(fileupload1.FileName.ToUpper());
            if ((sExe == ".JPG") || (sExe == ".JPEG") || (sExe == ".BITMAP") || (sExe == ".GIF") || (sExe == ".BMP"))
            {
                if (!Directory.Exists(Server.MapPath("data_banner/thumbnails")))
                    Directory.CreateDirectory(Server.MapPath("data_banner/thumbnails"));
                sSavePath = "data_banner/thumbnails/" + FileName + sExe;
                //Session["Psth"] = sSavePath;
                fileupload1.SaveAs(Server.MapPath("~\\data_banner/thumbnails\\" + FileName + sExe));
                str = FileName + sExe;
                // ImgUser.ImageUrl = "userphoto/" + FileName + sExe;
            }
            else
            {
                //lblmsg.Text = "File format not Valid!";
                return;
            }
        }
        else
        {
            string str1 = img3.Text.ToString();
            str=str1.Substring(23, str1.Length - 23);
            //int value2=Convert.ToInt32(sttt.Length);
            //str = sttt.Remove(23, value2);
        }
        Label lbl = (Label)gvDetails.Rows[e.RowIndex].FindControl("lblid");
        string strtid = lbl.Text.ToString();
        hst.Clear();
        ds.Clear();
        hst.Add("Action", "updategallary");
        hst.Add("name", strgal.Text);
        hst.Add("Id", strtid);
        hst.Add("image1", str);
        ds = kpcon.GetDataSet("usp_gallary", hst);
        bindgallery();
       // gvDetails.EditIndex = -1;

    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bindgaall();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "AddNew")
        {
            TextBox txtUsrname = (TextBox)GridView1.FooterRow.FindControl("txtftrusrname");
            DropDownList ddlgal = (DropDownList)GridView1.FooterRow.FindControl("ddlgal");
            FileUpload fileupload1 = (FileUpload)GridView1.FooterRow.FindControl("fileupload1");
            string FileName = string.Empty, sValidImage = string.Empty, sExe = string.Empty, sSavePath = string.Empty;
            string str;

            if (fileupload1.HasFile)
            {
                FileName = DateTime.Now.Day + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + "_" + DateTime.Now.Ticks;
                sValidImage = ".JPG,.JPEG,.BITMAP,.GIF,.BMP";
                sExe = System.IO.Path.GetExtension(fileupload1.FileName.ToUpper());
                if ((sExe == ".JPG") || (sExe == ".JPEG") || (sExe == ".BITMAP") || (sExe == ".GIF") || (sExe == ".BMP"))
                {
                    if (!Directory.Exists(Server.MapPath("data_banner/images")))
                        Directory.CreateDirectory(Server.MapPath("data_banner/images"));
                    sSavePath = "data_banner/images/" + FileName + sExe;
                    //Session["Psth"] = sSavePath;
                    fileupload1.SaveAs(Server.MapPath("~\\data_banner/images\\" + FileName + sExe));
                    str = FileName + sExe;
                    // ImgUser.ImageUrl = "userphoto/" + FileName + sExe;
                }
                else
                {
                    //lblmsg.Text = "File format not Valid!";
                    return;
                }
                hst.Clear();
                ds.Clear();
                hst.Add("action", "insertgaldesc");
                hst.Add("image1", str);
                hst.Add("id", ddlgal.SelectedValue.ToString());
                hst.Add("description", txtUsrname.Text.ToString());
                ds = kpcon.GetDataSet("usp_gallary", hst);
                bindgaall();
            }
        }
    }
    protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bindgaall();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label img3 = (Label)GridView1.Rows[e.RowIndex].FindControl("img3");
        string FileName = string.Empty, sValidImage = string.Empty, sExe = string.Empty, sSavePath = string.Empty;
        string str = "";
        TextBox strgal = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcom");
        FileUpload fileupload1 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("fileupload2");
     
       
        if (fileupload1.HasFile)
        {
            FileName = DateTime.Now.Day + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + "_" + DateTime.Now.Ticks;
            sValidImage = ".JPG,.JPEG,.BITMAP,.GIF,.BMP";
            sExe = System.IO.Path.GetExtension(fileupload1.FileName.ToUpper());
            if ((sExe == ".JPG") || (sExe == ".JPEG") || (sExe == ".BITMAP") || (sExe == ".GIF") || (sExe == ".BMP"))
            {
                if (!Directory.Exists(Server.MapPath("data_banner/images")))
                    Directory.CreateDirectory(Server.MapPath("data_banner/images"));
                sSavePath = "data_banner/images/" + FileName + sExe;
                //Session["Psth"] = sSavePath;
                fileupload1.SaveAs(Server.MapPath("~\\data_banner/images\\" + FileName + sExe));
                str = FileName + sExe;
                // ImgUser.ImageUrl = "userphoto/" + FileName + sExe;
            }
            else
            {
                //lblmsg.Text = "File format not Valid!";
                return;
            }
        }
        else
        {
      
            string str1 = img3.Text.ToString();
            str=str1.Substring(19, str1.Length - 19);
            //int value2=Convert.ToInt32(sttt.Length);
            //str = sttt.Remove(23, value2);
       
        }
        Label lbl = (Label)GridView1.Rows[e.RowIndex].FindControl("lblid");
        string strtid = lbl.Text.ToString();
        hst.Clear();
        ds.Clear();
        hst.Add("Action", "updategallrydec");
        hst.Add("description", strgal.Text);
        hst.Add("Id", strtid);
        hst.Add("image1", str);
        ds = kpcon.GetDataSet("usp_gallary", hst);
        bindgaall();
        // gvDetails.EditIndex = -1;

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

    }
    //.................this is the method for bind ythe gallery     by s
    public void bindgaall()
    {
        hst.Clear();
        ds.Clear();
        hst.Add("Action", "getgalleryforedit");
        ds = kpcon.GetDataSet("usp_gallary", hst);
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            GridView1.DataSource = ds;
            GridView1.DataBind();
            int columncount = GridView1.Rows[0].Cells.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "No Records Found";

        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            try
            {
                Hashtable hst1 = new Hashtable();
                DataTable dt1 = new DataTable();
                DataSet ds1 = new DataSet();
                //TextBox myTextBox = e.Row.FindControl("txtFooter") as TextBox;
                Label lbll = (Label)e.Row.FindControl("lblitemUsr");
                DropDownList ddlgal = (DropDownList)e.Row.FindControl("ddlgal");
                //DropDownList ddlsub = (DropDownList)grdata.FindControl("ddlsub");
                hst1.Clear();
                dt1.Clear();
                ds1.Clear();
                hst1.Add("Action", "getallvisalbum");

                ds1 = kpcon.GetDataSet("[usp_gallary]", hst1);
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    ddlgal.DataSource = ds1;
                    ddlgal.DataTextField = "gallaryname";
                    ddlgal.DataValueField = "Id";

                    ddlgal.DataBind();
                    ddlgal.Items.Insert(0, "------Selecet Gallary--");

                }
                else
                {
                    ddlgal.DataSource = ds1;


                    ddlgal.DataBind();
                    ddlgal.Items.Insert(0, "------No Gallary--");
                }
            }
            catch
            {
            }
        }

        if (e.Row.RowType == DataControlRowType.DataRow)
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
                Hashtable hst1 = new Hashtable();
                    DataTable dt1 = new DataTable();
                    DataSet ds1 = new DataSet();
                    //TextBox myTextBox = e.Row.FindControl("txtFooter") as TextBox;

                }
    }
}



Step-4:  gallery.aspx,in this page slider will be display

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

<!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 id="Head1" runat="server">
    <title></title><link rel="stylesheet" href="engine_banner/css/vlightbox.css" type="text/css" />
       
  <style type="text/css">#vlightbox a#vlb{display:none}
            </style>
  <link rel="stylesheet" href="engine_banner/css/visuallightbox.css" type="text/css" media="screen" />
<script src="engine_banner/js/jquery.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <table width="650px;">
<tr>





<td>
<asp:DataList ID="ddlgal"  runat="server"><ItemTemplate>

<div id="vlightbox"> <a class="vlightbox" href='<%#Eval("image")%>' id="a2" runat="server" title='<%#Eval("gallaryname")%>' >
<asp:Image ImageUrl='<%#Eval("image2")%>' runat="server" ID="img1" Width="150px" Height="110px" /></a>
    <a class="vlightbox" href='<%#Eval("image")%>' id="a1" runat="server" title='<%#Eval("description")%>'><asp:Image ImageUrl='<%#Eval("image")%>' runat="server" ID="img2" Width="150px" Height="110px" /></a></div></ItemTemplate></asp:DataList>
 <a id="vlb" href=""></a><script src="engine_banner/js/visuallightbox.js" type="text/javascript"></script>


</td>

</tr>





</table>
    </form>
</body>
</html>




Step 5 :gallaery.cs

using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.IO;
using AjaxControlToolkit;
using System.Text;

public partial class gallary : System.Web.UI.Page
{
    Hashtable hst = new Hashtable();
    DataTable dt = new DataTable();
    DataSet ds = new DataSet();
    ConnectionString kpcon = new ConnectionString();
    protected void Page_Load(object sender, EventArgs e)
    {
        bindgaall();
    }
    //.................this is the method for bind ythe gallery     by s
    public void bindgaall()
    {
        hst.Clear();
        ds.Clear();
        hst.Add("Action", "getgalleryforedit");
        ds = kpcon.GetDataSet("usp_gallary", hst);
        if (ds.Tables[0].Rows.Count > 0)
        {
            ddlgal.DataSource = ds;
            ddlgal.DataBind();
        }
        else
        {
            

        }
    }
}





No comments:

Post a Comment