AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Get the value from Modal Popup Gridview to parent window
Posted by Sreekanth Muntha on  4/12/2009 10:08:31 PM Category: AJAX
Add to my favorites
Email to friend
Hi,

I'm trying to have a modal popup with a sortable and pageable gridview on it. I'm opening the modal popup with server-side button click event. The popup opens fine. The GridView is attached to a SqlDataSource (this is a proof of concept for the modalpopup). The Save(one of the DataBound Field in Gridview) and Cancel buttons close the popup. OK so far. when I try to sort or page the gridview in the updatepanel. The sorting and paging occurs correctly. Now I want to get back the value of one of the column in the GridView to the back to page. I tried so many ways and could get the value from modal popup grid to back to the page. Please let me know how to code this. I am attaching my code below.

Thanks in advance.
Sreekanth.

Here's the markup:
-------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ 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>Untitled Page</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.Inactive
{
background-image: url('media/inactive-bg.gif');
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
.txtBox
{
border:none;
}
/* table style */
.datagrid
{
font-family:lucida grande,arial,helvetica,sans-serif;
font-size:11px;
width:800px;
border:solid 1px #ad9e87;
}

/* common cell styles */
.datagrid th, .datagrid td
{
cursor:default;
height:20px;
}

/* header cell style */
.datagrid th
{
border-right-style:solid;
border-right-width:1px;
border-right-color:#ad9e87;
border-bottom-style:solid;
border-bottom-width:2px;
border-bottom-color:#ad9e87;
background:#e1d6c7 url('media/mt_back.gif') repeat-x;
color:#59483f;
font-weight:bold;
text-align:center;
}

/* cell styles */
.datagrid td
{
color:#000;
padding:2px 8px;
border-right-style:solid;
border-right-width:1px;
border-right-color:#f2e8da;
border-bottom-style:solid;
border-bottom-width:1px;
border-bottom-color:#f2e8da;
}

/* mouseover row style */
.datagrid tr:hover{ background-color:#f2e8da; }
.detail
{
font-family:lucida grande,arial,helvetica,sans-serif;
font-size:11px;
background-color:#fff;
border:solid 2px #000;
padding:4px;
}
-->
</style>
<script type="text/javascript">
function onCancel() {
document.getElementById('<%=lit_Status.ClientID%>').value = 'You clicked Cancel.';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>ModalPopup Demo</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Show Dialog" OnClientClick="$find('ModalPopupExtender1').show(); return false;"/><br />
<asp:Label ID="ResponseLabel" runat="server" Width="367px" Font-Bold="True">No response</asp:Label>
<asp:TextBox ID="lit_Status" runat="server" Enabled="false" BorderColor="White" CssClass="txtBox"/><br />
<asp:Button ID="FakeTarget2" runat="server" Text="FakeTarget2" style="display:none"/>
<cc1:ModalPopupExtender id="ModalPopupExtender1" runat="server" TargetControlID="FakeTarget2"
PopupControlID="Panel1" CancelControlID="CloseButton" OkControlID="lnk_Number"
OnCancelScript="onCancel()" BackgroundCssClass="Inactive">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="detail" Width="700" Height="500">
&nbsp;some content in the popup <br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM [authors] Where State='CA'"
ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" PageSize="5" AllowPaging="True" AutoGenerateColumns="false"
onpageindexchanging="GridView1_PageIndexChanging" CssClass="datagrid" DataSourceID="SqlDataSource1"
GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged" DataKeyNames="au_id">
<Columns>
<asp:TemplateField>
<HeaderTemplate>ID</HeaderTemplate>
<ItemTemplate><asp:LinkButton ID="lnk_Number" runat="server" Text='<%# Eval("au_id") %>' OnClientClick="$find('ModalPopupExtender1').hide(); return false;"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="au_lname" HeaderText="LastName" ReadOnly="true" />
<asp:BoundField DataField="au_fname" HeaderText="FirstName" ReadOnly="true" />
<asp:BoundField DataField="phone" HeaderText="Phone" ReadOnly="true" />
<asp:BoundField DataField="address" HeaderText="Address" ReadOnly="true" />
<asp:BoundField DataField="city" HeaderText="City" ReadOnly="true" />
<asp:BoundField DataField="state" HeaderText="State" ReadOnly="true" />
<asp:BoundField DataField="zip" HeaderText="Zip" ReadOnly="true" />
<asp:BoundField DataField="contract" HeaderText="Contract" ReadOnly="true" />
</Columns>
</asp:GridView>
<asp:Button ID="CloseButton" runat="server" Text="Close" OnClientClick="$find('ModalPopupExtender1').hide(); return false;"/>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

Here's the code-behind:
-----------------------

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;


public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataBind();
}


///// Handles paging for GridView

protected void GridView1_PageIndexChanging( object sender, GridViewPageEventArgs e )
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
ResponseLabel.Text = Convert.ToString(this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value);
lit_Status.Text = Convert.ToString(this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value);
}
}

Post Your Reply Post New Question

 Viewer's Reply
This Question has 0 replies.

 
Sponsored by
FierceDeveloper
Introduction to Web Applications Development
The Art & Science of JavaScript - Free 100 Page Preview!