SourceCode
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Modalpopup.aspx.cs" Inherits="Modalpopup" %>
<%@ 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 runat="server">
<title>
</title>
<style type="text/css">
.ModalPopUpPanel
{
background-color: #FFFFFF;
border-color: #C2D5EE;
border-style: double;
border-width: 15px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcommand="GridView1_RowCommand" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" >
<Columns>
<asp:BoundField HeaderText="LedgerId" DataField="LedgerID" />
<asp:BoundField HeaderText="LedgerName" DataField="LedgerName" />
<asp:BoundField HeaderText="Company Id" DataField="CompanyID" />
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="linkView" runat="server" Text="View" CommandName="View" CommandArgument= '<%# Eval("LedgerID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="linkView1" runat="server" Text="ADD" CommandName="Add" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<a href="DisplayPage.aspx?LID=<%# Eval("LedgerID") %>">Edit</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
<asp:Panel ID="PanelModalPopUp" runat="server" Height="250px" Width="400px" CssClass="ModalPopUpPanel">
<table width="100%">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="LedgerId" />
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="LedgerName" />
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="CompanyId" />
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnOk" runat="server" Text="OK" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" onclick="btnUpdate_Click" />
<asp:Button ID="btndelete" runat="server" Text="Delete"
onclick="btndelete_Click" />
<asp:Button ID="Button2" runat="server" Text="Insert" onclick="Button2_Click" />
<asp:Button ID="btnreset" runat="server" Text="Reset"
onclick="btnreset_Click" />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:modalpopupextender ID="ModalPopupExtender1" runat="server" CancelControlID="btnOk" TargetControlID="Button1"
PopupControlID="PanelModalPopUp" BackgroundCssClass="ModalBackgroundCSS"></asp:modalpopupextender>
<asp:Button ID="Button1" runat="server" Text="Cancel" Style="display: none" />
</form>
</body>
</html>
C# Coading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Modalpopup : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=Satya-DBS\\Satya;database=Linku;uid=li;pwd=li212");
SqlDataAdapter da;
SqlCommand com;
DataSet ds;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
fillGrid();
}
Label4.Visible = false;
}
public void fillGrid()
{
da = new SqlDataAdapter("Select * from Rakesh", con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View")
{
ModalPopupExtender1.Show();
filldata(int.Parse(e.CommandArgument.ToString()));
}
else if (e.CommandName == "Add")
{
ModalPopupExtender1.Show();
}
}
public void filldata(int ledgerid)
{
da = new SqlDataAdapter("Select * from Rakesh where LedgerID='"+ ledgerid +"'", con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
dt = new DataTable();
da.Fill(dt);
TextBox1.Text = dt.Rows[0]["ledgerid"].ToString();
TextBox2.Text = dt.Rows[0]["LedgerName"].ToString();
TextBox3.Text = dt.Rows[0]["CompanyID"].ToString();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
int x = 0;
string up="update Rakesh set LedgerName='"+TextBox2.Text+"',CompanyId='"+ TextBox3.Text+"' where LedgerId="+TextBox1.Text+"";
//da = new SqlDataAdapter("del",con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(up,con);
x= com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text="Data Update Successfully";
fillGrid();
}
else
{
Label4.Text="Data Not Updated";
}
}
protected void btndelete_Click(object sender, EventArgs e)
{
int x = 0;
string de = "delete from Rakesh where LedgerId="+TextBox1.Text+"";
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(de,con);
x = com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text = "Data Deleted Successfully";
fillGrid();
}
else
{
Label4.Text = "Data Not Deleted Successfully";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
int x = 0;
string ins = "Insert into Rakesh values("+TextBox1.Text+",'"+TextBox2.Text+"',"+TextBox3.Text+")";
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(ins,con);
x = com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text = "Data Inserted Successfully";
fillGrid();
}
else
{
Label4.Text = "Data Not Inserted Successfully";
}
}
protected void btnreset_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
Database Table Design
Design
Run TimeDesign
when you click in the View Button Modal popup will be open You can edit when uyou want to add data you click in the Add Button OR you want to Edit Data Using Request Query String in Another Page though You Click in the Edit Button Go to Display Page Display Page Coding Are given Below
Display Page Source code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisplayPage.aspx.cs" Inherits="DisplayPage" %>
<!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></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 110px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="Ledger ID"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="LedgerName"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label3" runat="server" Text="Company ID"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Update" />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
C# Coading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class DisplayPage : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=Satya-DBS\\Satya;database=Linku;uid=li;pwd=li12011");
SqlDataAdapter da;
SqlCommand com;
DataSet ds;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString["LID"] != null)
{
GetDataByID(int.Parse(Request.QueryString["LID"].ToString()));
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int x = 0;
string up = "update Rakesh set LedgerName='" + TextBox2.Text + "',CompanyId='" + TextBox3.Text + "' where LedgerId=" + TextBox1.Text + "";
//da = new SqlDataAdapter("del",con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(up, con);
x = com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text = "Data Update Successfully";
}
else
{
Label4.Text = "Data Not Updated";
}
}
public void GetDataByID(int Lid)
{
da = new SqlDataAdapter("Select * from Rakesh where LedgerId='"+Request.QueryString["LID"].ToString()+"'", con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
dt = new DataTable();
da.Fill(dt);
TextBox1.Text = dt.Rows[0]["ledgerid"].ToString();
TextBox2.Text = dt.Rows[0]["LedgerName"].ToString();
TextBox3.Text = dt.Rows[0]["CompanyID"].ToString();
}
}
Design
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Modalpopup.aspx.cs" Inherits="Modalpopup" %>
<%@ 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 runat="server">
<title>
</title>
<style type="text/css">
.ModalPopUpPanel
{
background-color: #FFFFFF;
border-color: #C2D5EE;
border-style: double;
border-width: 15px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcommand="GridView1_RowCommand" BackColor="White"
BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" >
<Columns>
<asp:BoundField HeaderText="LedgerId" DataField="LedgerID" />
<asp:BoundField HeaderText="LedgerName" DataField="LedgerName" />
<asp:BoundField HeaderText="Company Id" DataField="CompanyID" />
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="linkView" runat="server" Text="View" CommandName="View" CommandArgument= '<%# Eval("LedgerID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="linkView1" runat="server" Text="ADD" CommandName="Add" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<a href="DisplayPage.aspx?LID=<%# Eval("LedgerID") %>">Edit</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
<asp:Panel ID="PanelModalPopUp" runat="server" Height="250px" Width="400px" CssClass="ModalPopUpPanel">
<table width="100%">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="LedgerId" />
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="LedgerName" />
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="CompanyId" />
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnOk" runat="server" Text="OK" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" onclick="btnUpdate_Click" />
<asp:Button ID="btndelete" runat="server" Text="Delete"
onclick="btndelete_Click" />
<asp:Button ID="Button2" runat="server" Text="Insert" onclick="Button2_Click" />
<asp:Button ID="btnreset" runat="server" Text="Reset"
onclick="btnreset_Click" />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:modalpopupextender ID="ModalPopupExtender1" runat="server" CancelControlID="btnOk" TargetControlID="Button1"
PopupControlID="PanelModalPopUp" BackgroundCssClass="ModalBackgroundCSS"></asp:modalpopupextender>
<asp:Button ID="Button1" runat="server" Text="Cancel" Style="display: none" />
</form>
</body>
</html>
C# Coading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Modalpopup : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=Satya-DBS\\Satya;database=Linku;uid=li;pwd=li212");
SqlDataAdapter da;
SqlCommand com;
DataSet ds;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
fillGrid();
}
Label4.Visible = false;
}
public void fillGrid()
{
da = new SqlDataAdapter("Select * from Rakesh", con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View")
{
ModalPopupExtender1.Show();
filldata(int.Parse(e.CommandArgument.ToString()));
}
else if (e.CommandName == "Add")
{
ModalPopupExtender1.Show();
}
}
public void filldata(int ledgerid)
{
da = new SqlDataAdapter("Select * from Rakesh where LedgerID='"+ ledgerid +"'", con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
dt = new DataTable();
da.Fill(dt);
TextBox1.Text = dt.Rows[0]["ledgerid"].ToString();
TextBox2.Text = dt.Rows[0]["LedgerName"].ToString();
TextBox3.Text = dt.Rows[0]["CompanyID"].ToString();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
int x = 0;
string up="update Rakesh set LedgerName='"+TextBox2.Text+"',CompanyId='"+ TextBox3.Text+"' where LedgerId="+TextBox1.Text+"";
//da = new SqlDataAdapter("del",con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(up,con);
x= com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text="Data Update Successfully";
fillGrid();
}
else
{
Label4.Text="Data Not Updated";
}
}
protected void btndelete_Click(object sender, EventArgs e)
{
int x = 0;
string de = "delete from Rakesh where LedgerId="+TextBox1.Text+"";
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(de,con);
x = com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text = "Data Deleted Successfully";
fillGrid();
}
else
{
Label4.Text = "Data Not Deleted Successfully";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
int x = 0;
string ins = "Insert into Rakesh values("+TextBox1.Text+",'"+TextBox2.Text+"',"+TextBox3.Text+")";
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(ins,con);
x = com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text = "Data Inserted Successfully";
fillGrid();
}
else
{
Label4.Text = "Data Not Inserted Successfully";
}
}
protected void btnreset_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
Database Table Design
Design
Run TimeDesign
when you click in the View Button Modal popup will be open You can edit when uyou want to add data you click in the Add Button OR you want to Edit Data Using Request Query String in Another Page though You Click in the Edit Button Go to Display Page Display Page Coding Are given Below
Display Page Source code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisplayPage.aspx.cs" Inherits="DisplayPage" %>
<!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></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 110px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="Ledger ID"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="LedgerName"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label3" runat="server" Text="Company ID"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Update" />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
C# Coading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class DisplayPage : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=Satya-DBS\\Satya;database=Linku;uid=li;pwd=li12011");
SqlDataAdapter da;
SqlCommand com;
DataSet ds;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString["LID"] != null)
{
GetDataByID(int.Parse(Request.QueryString["LID"].ToString()));
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int x = 0;
string up = "update Rakesh set LedgerName='" + TextBox2.Text + "',CompanyId='" + TextBox3.Text + "' where LedgerId=" + TextBox1.Text + "";
//da = new SqlDataAdapter("del",con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
com = new SqlCommand(up, con);
x = com.ExecuteNonQuery();
if (x > 0)
{
Label4.Text = "Data Update Successfully";
}
else
{
Label4.Text = "Data Not Updated";
}
}
public void GetDataByID(int Lid)
{
da = new SqlDataAdapter("Select * from Rakesh where LedgerId='"+Request.QueryString["LID"].ToString()+"'", con);
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
dt = new DataTable();
da.Fill(dt);
TextBox1.Text = dt.Rows[0]["ledgerid"].ToString();
TextBox2.Text = dt.Rows[0]["LedgerName"].ToString();
TextBox3.Text = dt.Rows[0]["CompanyID"].ToString();
}
}
Design
No comments:
Post a Comment