In this article i will tell you how you can create a dynamic jquery photo gallery or image gallery with text description in asp.net using c#.
Now first we will prepare a data base tableSo for this article create a new asp.net application and add a new page in this page add the below code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication7.WebForm1" %>
Dynamic jQuery Image Gallery With Text Description In Asp.Net Using C#
Now in your .cs page add the below code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text;
namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection objcon = new SqlConnection("Data Source=VINAY-809553B1F\\TSS;Initial Catalog=DEMO;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGallery();
}
}
private void BindGallery()
{
try
{
DataTable objdt = new DataTable();
string query = "select * from ImageGallery;";
SqlDataAdapter objda = new SqlDataAdapter(query, objcon);
objcon.Open();
objda.Fill(objdt);
objcon.Close();
StringBuilder objstring = new StringBuilder();
if (objdt.Rows.Count > 0)
{
for (int i = 0; i < objdt.Rows.Count; i++)
{
string classtext = "";
if (i == 0)
{
classtext = "class=`show`";
}
objstring.Append("");
objstring.Append("" + objdt.Rows[i]["ImageText"].ToString() + "
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text;
namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection objcon = new SqlConnection("Data Source=VINAY-809553B1F\\TSS;Initial Catalog=DEMO;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGallery();
}
}
private void BindGallery()
{
try
{
DataTable objdt = new DataTable();
string query = "select * from ImageGallery;";
SqlDataAdapter objda = new SqlDataAdapter(query, objcon);
objcon.Open();
objda.Fill(objdt);
objcon.Close();
StringBuilder objstring = new StringBuilder();
if (objdt.Rows.Count > 0)
{
for (int i = 0; i < objdt.Rows.Count; i++)
{
string classtext = "";
if (i == 0)
{
classtext = "class=`show`";
}
objstring.Append("");
objstring.Append("" + objdt.Rows[i]["ImageText"].ToString() + "
This is a demo text
`/>");objstring.Append("");
}
objstring.Append("
");
gallery.InnerHtml = objstring.ToString();
}
}
catch
{
}
}
}
}
Tags: Asp.Net , C#.Net , Javascript , jQuery
No comments:
Post a Comment
Note: only a member of this blog may post a comment.