<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="GridView_popup.aspx.cs"
Inherits="GridView_popup"
%>
<%@ Register
Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="cc1"
%>
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>Model
Popup in GridView Item Templatetitle>
<style>
.modalPopup
{
width:550;
height:650;
background-color:Gray;
}
style>
head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptM" runat="server">asp:ScriptManager>
<div>
<asp:GridView ID="gvEmployeeMLinq" runat="server" Width="50%" HorizontalAlign="Center" AutoGenerateColumns="false"
DataKeyNames="empId" AllowPaging="True"
onpageindexchanging="gvEmployeeMLinq_PageIndexChanging">
<AlternatingRowStyle BackColor="ActiveBorder" Font-Italic="true" />
<EmptyDataRowStyle BackColor="Azure" Font-Bold="true" />
<FooterStyle BackColor="AliceBlue" Font-Strikeout="true" />
<PagerStyle BackColor="Chocolate" ForeColor="ControlLight" />
<Columns>
<asp:TemplateField HeaderText="Task">
<ItemTemplate>
<asp:UpdatePanel ID="updateTaskPanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Label ID="lblTask" runat="server" />
<asp:Image ID="imgTask" runat="server" ImageUrl="~/roxocon.jpg" Width="25" Height="25" />
<cc1:PopupControlExtender ID="pceTask" runat="server"
TargetControlID="imgTask"
PopupControlID="popupPanelTask"
Position="Bottom" />
<asp:Panel ID="popupPanelTask" runat="server" CssClass="modalPopup" style="display:none;">
<asp:UpdatePanel ID="updatePopupTaskPanel" runat="server">
<ContentTemplate>
<table cellpadding="5" cellspacing="5" width="350px" height="250px">
<tr><td colspan="2"><asp:Label ID="lblTaskPopup"
runat="server"
Text='<%#Eval("empId")%>'>asp:Label><br />
<asp:Label ID="lblMsg" runat="server">asp:Label>
td>tr>
<tr><td>Nametd><td><asp:TextBox ID="txtName"
runat="server">asp:TextBox>td>tr>
<tr><td>Emailtd><td><asp:TextBox ID="txtEmail"
runat="server">asp:TextBox> td>tr>
<tr><td><asp:Button ID="btnPopupTaskOkay" runat="server" Text="OK"
OnClick="btnPopupTaskOkay_Click" UseSubmitBehavior="false"
/>td><td><asp:Button ID="btnPopupTaskCancel"
runat="server"
Text="Cancel"
OnClientClick='AjaxControlToolkit.PopupControlBehavior.__VisiblePopup.hidePopup();
return false;'
UseSubmitBehavior="false" />td>tr>
<tr><td colspan="2">
td>tr>
table>
ContentTemplate>
asp:UpdatePanel>
asp:Panel>
ContentTemplate>
asp:UpdatePanel>
ItemTemplate>
<ItemStyle Wrap="false" />
asp:TemplateField>
<asp:BoundField DataField="empName" HeaderText="Employee Name" />
<asp:BoundField DataField="Salary" HeaderText="Salary" />
Columns>
asp:GridView>
div>
form>
body>
html>
.aspx.cs
using System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
AjaxControlToolkit;
public partial class GridView_popup : System.Web.UI.Page
{
DataClassesDataContext
objLinq = new DataClassesDataContext(); //LINQ object
protected void Page_Load(object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BindGridView();
}
}
protected void btnPopupTaskOkay_Click(object
sender, EventArgs e)
{
Button
btn = (Button)sender;
GridViewRow
row = (GridViewRow)btn.NamingContainer;
PopupControlExtender
pce = AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page);
TextBox
txtName = (TextBox)row.FindControl("txtName");
TextBox
txtEmail = (TextBox)row.FindControl("txtEmail");
Label
lblMsg = (Label)row.FindControl("lblMsg");
if
(txtEmail.Text.Contains("@")
&& txtName.Text != "")
{
string
strName = txtName.Text;
string
strEmail = txtEmail.Text;
lblMsg.ForeColor = System.Drawing.Color.Green;
lblMsg.Text = "Your message has been reached to us. ";
//System.Threading.Thread.Sleep(1000);
//pce.Cancel();
lblMsg.Text = "";
txtName.Text = "";
txtEmail.Text = "";
}
else
{
lblMsg.ForeColor = System.Drawing.Color.Red;
lblMsg.Text = "Please enter name and Email.";
}
}
protected void BindGridView()
{
var dt
= from emp in
objLinq.EmployeeMasters
join
empT in objLinq.EmployeePhones
on
emp.empId equals empT.empId
select
new
{
empId = emp.empId,
empName = emp.empName,
salary = emp.salary
};
gvEmployeeMLinq.DataSource = dt;
gvEmployeeMLinq.DataBind();
}
protected void gvEmployeeMLinq_PageIndexChanging(object sender, GridViewPageEventArgs
e)
{
gvEmployeeMLinq.PageIndex =
e.NewPageIndex;
BindGridView();
}
}
Comments