Create table
CREATE TABLE USERS
(
ID int IDENTITY(1,1) ,
Name varchar(50) ,
Email varchar(100) ,
CreateDate datetime
)
/***********************gridwiththemes.aspx*********************/
<asp:ObjectDataSource ID="ThemeDataSource" runat="server" SelectMethod="GetThemes"
TypeName="ThemeManager"></asp:ObjectDataSource>
<br />
<br />
<asp:DropDownList ID="themelist" runat="server" DataTextField="name" DataValueField="name"
OnSelectedIndexChanged="themelist_SelectedIndexChanged" DataSourceID="ThemeDataSource"
OnDataBound="themelist_DataBound" AutoPostBack="true">
<div>
<br />
<asp:Button ID="btnsubmit" Text="Submit" runat="server" />
</div>
<div>
<asp:GridView ID="gvUser" DataKeyNames="ID" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a id="linkDelete" runat="server" href="#">
<img src="Update.jpg" alt=""></a>
<asp:Button runat="server" CommandName="Delete" ID="btnDelete" Style="display: none;" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="select" Text="Edit" runat="server" CommandName="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
<asp:BoundField DataField="EMAIL" HeaderText="EMAIL" SortExpression="EMAIL" />
<asp:BoundField DataField="CREATEDATE" HeaderText="CREATEDATE" SortExpression="CREATEDATE" />
</Columns>
</asp:GridView>
</div>
/************************gridwiththemes.aspx.cs***************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class gridwiththemes : BasePage
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["MyConnection"].ToString());
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
protected void themelist_DataBound(object sender, EventArgs e)
{
themelist.SelectedValue = Page.Theme;
}
protected void themelist_SelectedIndexChanged(object sender, EventArgs e)
{
Session["themename"] = themelist.SelectedValue;
Session.Add("MyTheme", Session["themename"].ToString());
Server.Transfer(Request.FilePath);
}
private void BindGrid()
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from USERS";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
gvUser.DataSource = dt;
gvUser.DataBind();
con.Close();
}
}
/****************************************************************
Create App_Code folder and take three .cs file
1. BasePage.cs
2. Theme.cs
3. ThemeManager.cs
/*************
1. BasePage.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class BasePage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if (Session["MyTheme"] == null)
{
Session.Add("MyTheme", "first");
Page.Theme = ((string)Session["MyTheme"]);
}
else
{
Page.Theme = ((string)Session["MyTheme"]);
}
}
}
/*************
1. Theme.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class Theme
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
public Theme(string name)
{
Name = name;
}
}
/*************
3. ThemeManager.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class ThemeManager
{
public static List<Theme> GetThemes()
{
DirectoryInfo dInfo = new DirectoryInfo(
System.Web.HttpContext.Current.Server.MapPath("App_Themes"));
DirectoryInfo[] dArrInfo = dInfo.GetDirectories();
List<Theme> list = new List<Theme>();
foreach (DirectoryInfo sDirectory in dArrInfo)
{
Theme temp = new Theme(sDirectory.Name);
list.Add(temp);
}
return list;
}
}
/**********************
Create folder App_Themes
Create two skin file...your can take more as per requirement.
********************/
we have took two skin file
1. first
2. second
/**************** first.skin ******************************/
<asp:GridView runat="server" AutoGenerateColumns="False" BorderWidth="1" CssClass="GridViewStyle1" GridLines="both" cellpadding="3">
<AlternatingRowStyle HorizontalAlign=Center />
<RowStyle HorizontalAlign=Center />
<HeaderStyle HorizontalAlign=Center CssClass="HeaderStyle1" />
<PagerStyle HorizontalAlign=right CssClass="PagerStyle1" />
</asp:GridView>
<asp:Button runat="server" CssClass="btnbghome"></asp:Button>
/**************** second.skin ******************************/
<asp:GridView runat="server" AutoGenerateColumns="False" BorderColor="#EBE4DE" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" EmptyDataText="There are no data records to display." ForeColor="Black" GridLines="Vertical" style="margin-top:2em;" width="100%" skinid="glossygrid1">
<FooterStyle BackColor="#FAEBE7" />
<RowStyle BackColor="#EBE4DE"/>
<PagerStyle BackColor="#EBE4DE" ForeColor="#F369B1" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#FAEBE7" Font-Bold="True" ForeColor="573922" />
<HeaderStyle BackColor="#FAEBE7" Font-Bold="True" ForeColor="#573922" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="Transparent" />
</asp:GridView>
<asp:Button runat="server" CssClass="btnbghome"></asp:Button>
/**************************Take css file ********
.GridViewStyle1 { font-family: "Lucida Grande", "Trebuchet MS", Verdana, Helvetica, sans-serif; font-size: 11px;
border:1px solid #000000; }
.GridViewStyle1 th td { border:1px solid #000000; }
.GridViewStyle1 td { border:1px solid #CCCCCC; border-bottom:1px solid #000000; border-left:1px solid #000000; border-right:1px solid #000000; }
.HeaderStyle1,
.PagerStyle1 { background-image: url(../../backoffice/assets/glossyback1.gif); background-position:center; background-repeat:repeat-x; background-color:#384F8D; height:15px; color:#FFFFFF; }
.HeaderStyle1 th { padding: 3px; color: #FFFFFF; border-top:1px solid #000000; border-left:1px solid #000000; border-right:1px solid #000000; }
.HeaderStyle1 a { text-decoration:none; color:#000000; display:block; text-align:left; font-weight:bold; }
.PagerStyle1 a { color:#FFFFFF; display:block; text-align:left; font-weight:bold; padding:2px 2px 2px 2px;}
.PagerStyle1 span { font-weight:bold; color:#fff; text-decoration:none; padding:2px 2px 2px 2px; }
.RowStyle1 td,
.AltRowStyle1 td,
.SelectedRowStyle1 td,
.EditRowStyle1 td { padding: 3px; }
.RowStyle1 td { background-color: #ffffff; height: 15px; }
.AltRowStyle1 td { background-color: #B4D0F2; height: 15px; }
.SelectedRowStyle1 td { background-color: #ffff66; height: 15px; }
.GridViewStyle { font-family: "Lucida Grande", "Trebuchet MS", Verdana, Helvetica, sans-serif; font-size:small; table-layout: auto; border-collapse: collapse; border: #1d1d1d 5px solid; }
.HeaderStyle,
.PagerStyle { background-image: url(../../backoffice/assets/HeaderGlassBlack.jpg); background-position:center; background-repeat:repeat-x; background-color:#1d1d1d; }
.HeaderStyle th { padding: 5px; color: #ffffff; }
.HeaderStyle a { text-decoration:none; color:#ffffff; display:block; text-align:left; font-weight:normal; }
.PagerStyle table. {
text-align:center;
margin:auto;
}