Dynamic News and Events Displaying in the Website using Marquee for Home page:
Setp 1: (Note : Mysql database ):
Create a new database Named "jk" and table "newsevents".
Here is the commands used for Mysql database:-
Show databases;
Create database jk;
Use jk;
create table newsevents(sno int primary key
auto_increment,date varchar(75), time varchar(75), venue varchar(200), topic
varchar(500), takenby varchar(100), createdat varchar(50), createdby varchar(100), createdon date, ractive varchar(1));
Select * from newsevents;
Setp 2:Create the new empty web site for Visual Studio.
Add the new items .Empty web form.Rename it ''dynamiceventz.aspx" with Master Page.
Here is the snippets for entire page.
Aspx Page:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="dynamiceventz.aspx.cs" Inherits="dynamiceventz" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
<br />
<br />
<div id="dv" runat="server" style="border:solid ; background-color:aqua; width: 337px; height: 186px;">
<div style="height: 183px; width: 341px" >
<marquee scrolldelay="300" direction="up" onmouseover='this.stop();'
onmouseout="this.start();" style="height: 181px; width: 341px">
<asp:Label ID="news" runat="server" Font-Bold="true" Text="Events">
</asp:Label></marquee>
</div>
</div>
<br />
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Newsevents.aspx">Add New Events</asp:HyperLink>
</div>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
<br />
<br />
<div id="dv" runat="server" style="border:solid ; background-color:aqua; width: 337px; height: 186px;">
<div style="height: 183px; width: 341px" >
<marquee scrolldelay="300" direction="up" onmouseover='this.stop();'
onmouseout="this.start();" style="height: 181px; width: 341px">
<asp:Label ID="news" runat="server" Font-Bold="true" Text="Events">
</asp:Label></marquee>
</div>
</div>
<br />
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Newsevents.aspx">Add New Events</asp:HyperLink>
</div>
</asp:Content>
C# Page:
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Globalization;
public partial class dynamiceventz : System.Web.UI.Page
{
MySqlConnection Conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillNews();
}
}
private void FillNews()
{
string Date = null;
string mdate = "";
Conn.Open();
MySqlCommand cm = new MySqlCommand("select count(*) from newsevents", Conn);
int co = Convert.ToInt32(cm.ExecuteScalar());
if (co == 0)
{
mdate = "Events Updating in Progress";
news.Text = mdate;
Conn.Close();
}
else
{
String strQuery = "select date,time,venue,topic,takenby from newsevents";
MySqlCommand cmdd = new MySqlCommand(strQuery, Conn);
MySqlDataAdapter daa = new MySqlDataAdapter(cmdd);
DataSet dss = new DataSet();
daa.Fill(dss);
foreach (DataRow row in dss.Tables[0].Rows)
{
string breakTag = "<br>";
Date = "DATE:" + row["date"].ToString() + breakTag +
"TIME:" + row["time"].ToString() + breakTag +
"VENUE: " + row["Venue"].ToString() + breakTag +
"TOPIC:" + row["topic"].ToString() + breakTag +
"TAKEN BY:" + row["takenby"].ToString() + breakTag;
mdate = mdate + breakTag + Date;
}
news.Text = mdate;
}
Conn.Close();
}
}
Setp 3:Add another new empty web page.
Add the new items .Empty web form.Rename it ''Newsevn" with Master Page.
Here is the snippets for entire page.
Aspx Page:
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="custom-scrollbars.css" rel="stylesheet" type="text/css" />
<link href="NewContainer.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#cssmenu {
float: left;
width: 100%;
font-size: 93%;
line-height: normal;
border-bottom: 4px solid #696865;
background-color: #f2f2f2;
}
#cssmenu ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
#cssmenu li {
display: block;
position: relative;
float: left;
}
#cssmenu a {
float: left;
background-color:#f2f2f2;
margin: 0;
padding: 0 0 0 4px;
text-decoration: none;
}
#cssmenu a span
{
color:#F7F7F3;
padding:0.55em 2.95em;
margin-right:0.01em;
border-radius:6px 6px 0 0;
float: left;
display: block;
background-color: #696865;
height: 15px;
color: white;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#cssmenu a span {
float: none;
}
/* End IE5-Mac hack */
#cssmenu .active a span,
#cssmenu a:hover span {
color: #FFFFFF;
background-color:#2798B0;
}
#cssmenu .active a,
#cssmenu a:hover {
background-position: 0 -10px;
}
#cssmenu .active a span,
#cssmenu a:hover span {
background-position: 100% -10px;
}
:focus
{
background-color:Silver;
}
.label_Font
{
font-family:verdana,tahoma,helvetica;
font-size:14px;
color:Black;
}
.label_Font1
.Aabel_Font
{
font-family:verdana,tahoma,helvetica;
font-size:14px;
color:Black;
}
.style1
{
width: 100%;
}
.txt
{
border: 1px solid #000000;
text-transform:uppercase;
}
.buttonnew
{
border-top: 1px solid #96d1f8;
background: #65a9d7;
background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
background: -webkit-linear-gradie nt(top, #3e779d, #65a9d7);
background: -moz-linear-gradient(top, #3e779d, #65a9d7);
background: -ms-linear-gradient(top, #3e779d, #65a9d7);
background: #336699;
padding: 5px 10px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
-moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: white;
font-size: 17px;
text-decoration: none;
vertical-align: middle;
text-align: center;
}
.button:hover {
border-top-color: #28597a;
background: #28597a;
color: #ccc;
}
.button:active {
border-top-color: #1b435e;
background: #1b435e;
}
.myButton {
background-color:#44c767;
-moz-border-radius:28px;
-webkit-border-radius:28px;
border-radius:28px;
border:1px solid #18ab29;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:arial;
font-size:17px;
padding:16px 31px;
text-decoration:none;
text-shadow:0px 1px 0px #2f6627;
}
.myButton:hover {
background-color:#5cbf2a;
}
.myButton:active {
position:relative;
top:1px;
}
.style10
{
font-family: verdana,tahoma,helvetica;
font-size: 14px;
color: Black;
width: 191px;
}
.style12
{
}
.style13
{
height: 410px;
}
.style14
{
}
.style16
{
font-family: verdana,tahoma,helvetica;
font-size: 14px;
color: Black;
width: 141px;
}
.style17
{
font-family: verdana,tahoma,helvetica;
font-size: 14px;
color: Black;
width: 52px;
}
.style20
{
width: 52px;
}
.style22
{
width: 192px;
}
.style24
{
font-family: verdana,tahoma,helvetica;
font-size: 14px;
color: Black;
width: 683px;
}
.style25
{
width: 683px;
}
.style33
{
width: 181px;
}
.style34
{
width: 185px;
}
.style41
{
width: 240px;
height: 46px;
}
.style43
{
width: 88px;
height: 30px;
}
.style44
{
width: 23px;
height: 46px;
}
.style45
{
height: 46px;
}
.style46
{
width: 88px;
height: 46px;
}
.style48
{
width: 240px;
height: 51px;
}
.style50
{
width: 88px;
height: 51px;
}
.style51
{
width: 23px;
height: 51px;
}
.style55
{
width: 88px;
height: 45px;
}
.style56
{
width: 23px;
height: 45px;
}
.style57
{
height: 45px;
}
.style58
{
width: 387px;
height: 47px;
}
.style60
{
width: 145px;
height: 47px;
}
.style61
{
width: 88px;
height: 47px;
}
.style62
{
width: 23px;
height: 47px;
}
.style63
{
height: 47px;
}
.style64
{
width: 240px;
height: 47px;
}
.style65
{
font-family: verdana,tahoma,helvetica;
font-size: 14px;
color: Black;
height: 45px;
}
.auto-style1 {
height: 46px;
width: 107px;
}
.auto-style2 {
height: 47px;
width: 107px;
}
.auto-style3 {
width: 241px;
height: 51px;
}
.auto-style4 {
width: 241px;
height: 46px;
}
.auto-style5 {
height: 47px;
}
.auto-style7 {
width: 241px;
height: 49px;
}
.auto-style9 {
width: 23px;
height: 49px;
}
.auto-style10 {
height: 49px;
width: 107px;
}
.auto-style26 {
width: 436px;
height: 47px;
}
.auto-style33 {
width: 436px;
}
.auto-style34 {
font-family: verdana,tahoma,helvetica;
font-size: 14px;
color: Black;
width: 436px;
}
.auto-style36 {
width: 436px;
height: 51px;
}
.auto-style37 {
width: 211px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ToolkitScriptManager ID="tools" runat="server"></asp:ToolkitScriptManager>
<div style="height:auto; background-color :#f2f2f2; margin-top:20px;">
<br />
<asp:Panel ID="pregpanel" runat="server" ForeColor ="Black" Font-Size ="21px" BackColor="#f2f2f2" Width ="1150px" Height="40PX">
<center><b> NEWS & EVENTS</b></center>
</asp:Panel>
<asp:UpdatePanel ID="updates" runat="server">
<ContentTemplate>
<div align="left">
<asp:TabContainer ID="TabContainer1" runat="server" Width="1150px"
BackColor="#f2f2f2" CssClass="ajax__tab_red-theme"
style="margin-right: 0px" ActiveTabIndex="1" AutoPostBack="True">
<asp:TabPanel ID="ta" runat="server">
<HeaderTemplate>ADD</HeaderTemplate>
<ContentTemplate>
<table style="width: 100%;">
<tr>
<td align="right" class="auto-style36">
<asp:Label ID="lbldate" runat="server" CssClass="label_Font" Text="Date :"></asp:Label>
</td>
<td class="auto-style3" colspan="3">
<asp:TextBox ID="txtdate" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="23px" TabIndex="7" Width="209px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtdate" ErrorMessage="*" ForeColor="Red" ValidationGroup="j"></asp:RequiredFieldValidator>
</td>
<td class="style51"></td>
</tr>
<tr>
<td align="right" class="auto-style33">
<asp:Label ID="lbltime" runat="server" CssClass="label_Font" Text="Time :"></asp:Label>
</td>
<td class="auto-style7" colspan="3">
<asp:TextBox ID="txttime" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="23px" TabIndex="7" Width="209px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txttime" ErrorMessage="*" ForeColor="Red" ValidationGroup="j"></asp:RequiredFieldValidator>
</td>
<td class="auto-style9">
</td>
<td class="auto-style10">
</td>
</tr>
<tr>
<td align="right" class="auto-style34">
<asp:Label ID="lblvenue" runat="server" CssClass="label_Font" Text="Venue:"></asp:Label>
</td>
<td class="auto-style4" colspan="3">
<asp:TextBox ID="txtvenue" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="86px" TabIndex="7" Width="209px" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtvenue" ErrorMessage="*" ForeColor="Red" ValidationGroup="j"></asp:RequiredFieldValidator>
</td>
<td class="style44">
</td>
<td class="auto-style1"> </td>
</tr>
<tr>
<td align="right" class="auto-style34">
<asp:Label ID="lbltopic" runat="server" CssClass="label_Font" Text="Topic:"></asp:Label>
</td>
<td class="auto-style4" colspan="3">
<asp:TextBox ID="txttopic" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="113px" TabIndex="7" Width="209px" TextMode="MultiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txttopic" ErrorMessage="*" ForeColor="Red" ValidationGroup="j"></asp:RequiredFieldValidator>
</td>
<td class="style44"> </td>
<td class="auto-style1"> </td>
</tr>
<tr>
<td align="right">
<asp:Label ID="lbltakenby" runat="server" CssClass="label_Font" Text="Taken By:"></asp:Label>
</td>
<td align="left" colspan="3">
<asp:TextBox ID="txttakby" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="86px" TabIndex="7" TextMode="MultiLine" Width="209px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txttakby" ErrorMessage="*" ForeColor="Red" ValidationGroup="j"></asp:RequiredFieldValidator>
</td>
<td class="style62">
</td>
<td class="auto-style2">
</td>
</tr>
<tr>
<td class="auto-style26"></td>
<td align="center" class="auto-style37">
<asp:Button ID="btnsubmit" runat="server" BackColor="#696865" CssClass="buttonnew" ForeColor="White" Height="31px" OnClick="btnsubmit_Click" style="font-size: medium; " TabIndex="6" Text="Submit" ValidationGroup="j" />
</td>
<td align="right" class="auto-style5"> </td>
<td align="right" class="style63"> </td>
<td class="style62"></td>
<td class="auto-style2"></td>
</tr>
</table>
<div>
<table width="100%">
<tr>
<td>
</td>
</tr>
<tr>
<td class="style13">
<div style=" overflow:scroll; height:374px; width:97%;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#F2F2F2" BorderStyle="None" BorderWidth="1px" CellPadding="3" EmptyDataText="No records has been added" Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:UpdatePanel ID="buttonupd" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="deleterows" Text="Delete" />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="date" HeaderText="DATE">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="time" HeaderText="TIME">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="venue" HeaderText="VENUE">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="topic" HeaderText="TOPIC">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="takenby" HeaderText="TAKEN BY">
<ItemStyle Width="120px" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#696865" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</div>
</td>
</tr>
<tr>
<td class="style12" align="center">
</td>
</tr>
<tr>
<td class="style12" align="center">
</td>
</tr>
<tr>
<td class="style12" align="center">
<asp:Button ID="btnsave" runat="server" BackColor="#696865" CssClass="buttonnew" ForeColor="White" style="font-size: medium; height: 32px;" TabIndex="6" Text="Save" OnClick="btnsave_Click1" />
<asp:Button ID="btnclear" runat="server" BackColor="#696865" CssClass="buttonnew" ForeColor="White" style="font-size: medium; height: 32px;" TabIndex="7" Text="Clear" OnClick="btnclear_Click" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="mod" runat="server">
<HeaderTemplate>
MODIFY</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<br />
<div style="background-color:#f2f2f2";>
<center> <asp:Button runat="server" Text="Click To Modify Events" BackColor="#696865" CssClass="buttonnew" ForeColor="White" Height="31px" TabIndex="6" ID="btnview" style="font-size: medium; " OnClick="btnview_Click"></asp:Button>
</center>
</div>
<center>
<div id="abc" runat="server" visible="false" style="background-color:#f2f2f2; width: 1010px; height:304px; overflow:scroll;" vis>
<table align="center" width="600px">
<tr>
<td align="center" colspan="2"> </td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="gvEmployeeDetails" runat="server" AutoGenerateColumns="false" HeaderStyle-BackColor="#4D4D4D" HeaderStyle-ForeColor="White" onrowcancelingedit="gvEmployeeDetails_RowCancelingEdit" onrowcommand="gvEmployeeDetails_RowCommand" onrowdeleting="gvEmployeeDetails_RowDeleting" onrowediting="gvEmployeeDetails_RowEditing" onrowupdating="gvEmployeeDetails_RowUpdating" ShowFooter="true" Width="853px" Height="229px">
<Columns>
<asp:TemplateField HeaderText="SNO">
<ItemTemplate>
<asp:Label ID="lblsno" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "sno") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lbleditsno" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "sno") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DATE">
<ItemTemplate>
<asp:Label ID="lbldat" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "date") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txteditdat" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "date") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtadddat" runat="server" Width="100px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TIME">
<ItemTemplate>
<asp:Label ID="lbltim" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "time") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtedittim" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "time") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtaddtim" runat="server" Width="150px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VENUE">
<ItemTemplate>
<asp:Label ID="lblven" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "venue") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txteditven" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "venue") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtaddven" runat="server" Width="150px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TOPIC">
<ItemTemplate>
<asp:Label ID="lbltop" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "topic") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtedittop" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "topic") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtaddtop" runat="server" Width="150px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TAKEN BY">
<ItemTemplate>
<asp:Label ID="lbltakenby" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "takenby") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtedittakenby" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "takenby") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtaddtakenby" runat="server" Width="150px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UPDATE/DELETE">
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" runat="server" CommandName="Edit" Height="32px" ImageUrl="~/Images/icon-edit.png" Width="32px" />
<asp:ImageButton ID="imgbtnDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/Delete.png" />
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID="imgbtnUpdate" runat="server" CommandName="Update" ImageUrl="~/Images/icon-update.png" />
<asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/Images/icon-Cancel.png" />
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lbtnAdd" runat="server" CommandName="ADD" Text="Add" Width="80px"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</center>
<br />
</ContentTemplate></asp:UpdatePanel>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
Screen Shot:
C# Page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Drawing;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Text;
using System.Collections.Specialized;
using System.Web.Services;
public partial class Newsevents : System.Web.UI.Page
{
MySqlConnection con1 = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ConnectionString);
string createdon;
string user;
string ipaddr;
string curdate;
string createdby;
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5] { new DataColumn("date"), new DataColumn("time"), new DataColumn("venue"), new DataColumn("topic"),new DataColumn("takenby") });
ViewState["jkt"] = dt;
this.BindGrid();
abc.Visible =false;
}
string strHostName = null;
strHostName = System.Net.Dns.GetHostName();
ipaddr = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
createdon = DateTime.Now.ToString("yyyy-MM-dd");
curdate = DateTime.Now.ToString("yyyyMMdd");
createdby = "Admin";
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
add();
txtdate.Text = "";
txttime.Text = "";
txttopic.Text = "";
txtvenue.Text = "";
txttakby.Text = "";
}
protected void add()
{
dt = (DataTable)ViewState["jkt"];
dt.Rows.Add(txtdate.Text, txttime.Text, txtvenue.Text, txttopic.Text,txttakby.Text);
ViewState["jkt"] = dt;
this.BindGrid();
}
protected void BindGrid()
{
GridView1.DataSource = (DataTable)ViewState["jkt"];
GridView1.DataBind();
}
protected void btnclear_Click(object sender, EventArgs e)
{
GridView1.DataSource = null;
GridView1.DataBind();
dt = (DataTable)ViewState["jkt"];
dt.Clear();
}
protected void deleterows(object sender, EventArgs e)
{
Button lb = (Button)sender;
GridViewRow gvRow = (GridViewRow)lb.NamingContainer;
int rowID = gvRow.RowIndex + 0;
if (ViewState["jkt"] != null)
{
dt = (DataTable)ViewState["jkt"];
if (dt.Rows.Count >= 1)
{
if (gvRow.RowIndex < dt.Rows.Count)
{
dt.Rows.Remove(dt.Rows[rowID]);
}
if (dt.Rows.Count == 0)
{
dt = (DataTable)ViewState["jkt"];
dt.Clear();
}
}
//Store the current data in ViewState for future reference
ViewState["jkt"] = dt;
////Re bind the GridView for the updated data
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void btnsave_Click1(object sender, EventArgs e)
{
DataTable dt = (DataTable)ViewState["jkt"];
dt = dt.DefaultView.ToTable(true, "date", "time", "venue", "topic","takenby");
GridView1.DataSource = dt;
GridView1.DataBind();
con1.Open();
MySqlTransaction tran = con1.BeginTransaction();
try
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
string datee = GridView1.Rows[i].Cells[1].Text;
string timee = GridView1.Rows[i].Cells[2].Text;
string venuee = GridView1.Rows[i].Cells[3].Text;
string topicc = GridView1.Rows[i].Cells[4].Text;
string takenbyy = GridView1.Rows[i].Cells[5].Text;
MySqlCommand cmdl = new MySqlCommand("insert into newsevents(date,time,venue,topic,takenby,createdat,createdby,createdon,ractive)values('" + datee + "','" + timee + "','" + venuee + "','" + topicc + "','"+takenbyy+"','" + ipaddr + "','" + createdby + "','" + createdon + "','Y')", con1, tran);
cmdl.ExecuteNonQuery();
}
tran.Commit();
dt = (DataTable)ViewState["jkt"];
dt.Clear();
GridView1.DataSource = null;
GridView1.DataBind();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmessage", "alert('Inserted successfully')", true);
}
catch (Exception)
{
tran.Rollback();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmessage", "alert('Not Submitted Sucessfully')", true);
}
con1.Close();
}
//Update start
protected void BindData()
{
DataSet ds = new DataSet();
DataTable FromTable = new DataTable();
try
{
con1.Open();
string cmdstr = "select * from newsevents";
MySqlCommand cmd = new MySqlCommand(cmdstr, con1);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
adp.Fill(ds);
cmd.ExecuteNonQuery();
FromTable = ds.Tables[0];
if (FromTable.Rows.Count > 0)
{
gvEmployeeDetails.DataSource = FromTable;
gvEmployeeDetails.DataBind();
}
else
{
FromTable.Rows.Add(FromTable.NewRow());
gvEmployeeDetails.DataSource = FromTable;
gvEmployeeDetails.DataBind();
int TotalColumns = gvEmployeeDetails.Rows[0].Cells.Count;
gvEmployeeDetails.Rows[0].Cells.Clear();
gvEmployeeDetails.Rows[0].Cells.Add(new TableCell());
gvEmployeeDetails.Rows[0].Cells[0].ColumnSpan = TotalColumns;
gvEmployeeDetails.Rows[0].Cells[0].Text = "No records Found";
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
ds.Dispose();
con1.Close();
}
}
protected void gvEmployeeDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label lblsno = (Label)gvEmployeeDetails.Rows[e.RowIndex].FindControl("lblsno");
con1.Open();
string cmdstr = "delete from newsevents where sno=?sno";
MySqlCommand cmd = new MySqlCommand(cmdstr, con1);
cmd.Parameters.AddWithValue("?sno", lblsno.Text);
cmd.ExecuteNonQuery();
con1.Close();
BindData();
}
protected void gvEmployeeDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("ADD"))
{
TextBox txtadddat = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtadddat");
TextBox txtaddtim = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtaddtim");
TextBox txtaddven = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtaddven");
TextBox txtaddtop = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtaddtop");
TextBox txtaddtakenby = (TextBox)gvEmployeeDetails.FooterRow.FindControl("txtaddtakenby");
con1.Open();
string cmdstr = "insert into newsevents(date,time,venue,topic,takenby) values(?date,?time,?venue,?topic,?takenby)";
MySqlCommand cmd = new MySqlCommand(cmdstr, con1);
cmd.Parameters.AddWithValue("?date", txtadddat.Text);
cmd.Parameters.AddWithValue("?time", txtaddtim.Text);
cmd.Parameters.AddWithValue("?venue", txtaddven.Text);
cmd.Parameters.AddWithValue("?topic", txtaddtop.Text);
cmd.Parameters.AddWithValue("?takenby", txtaddtakenby.Text);
cmd.ExecuteNonQuery();
con1.Close();
BindData();
}
}
protected void gvEmployeeDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txteditdat = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txteditdat");
TextBox txtedittim = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txtedittim");
TextBox txteditven = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txteditven");
TextBox txtedittop = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txtedittop");
Label txteditsno = (Label)gvEmployeeDetails.Rows[e.RowIndex].FindControl("lbleditsno");
TextBox txtedittakenby = (TextBox)gvEmployeeDetails.Rows[e.RowIndex].FindControl("txtedittakenby");
con1.Open();
string cmdstr = "update newsevents set date=?date,time=?time,venue=?venue,topic=?topic,takenby=?takenby where sno=?sno";
MySqlCommand cmd = new MySqlCommand(cmdstr, con1);
cmd.Parameters.AddWithValue("?date", txteditdat.Text);
cmd.Parameters.AddWithValue("?time", txtedittim.Text);
cmd.Parameters.AddWithValue("?venue", txteditven.Text);
cmd.Parameters.AddWithValue("?topic", txtedittop.Text);
cmd.Parameters.AddWithValue("?sno", txteditsno.Text);
cmd.Parameters.AddWithValue("?takenby", txtedittakenby.Text);
cmd.ExecuteNonQuery();
con1.Close();
gvEmployeeDetails.EditIndex = -1;
BindData();
}
protected void gvEmployeeDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvEmployeeDetails.EditIndex = -1;
BindData();
}
protected void gvEmployeeDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
gvEmployeeDetails.EditIndex = e.NewEditIndex;
BindData();
}
protected void btnview_Click(object sender, EventArgs e)
{
BindData();
abc.Visible = true;
}
}
Setp 4:Video Examples And Source Code Download-
Use below Link to download full source code:
Preview Output:
Preview Output:
Full Example:
No comments:
Post a Comment