|
Article relates to
|
RadGrid
RadWindow
|
|
Created by
|
Stephen, Telerik
|
|
Last modified by
|
Iana, Telerik
|
HOW-TO
Pass data to parent page from RadGrid displayed in RadWindow
DESCRIPTION
There are cases in which you may want to visualize grid instance in pop-up window and channel data to the opener page in par with the user actions undertook in the modal window. This article demonstrates how to combine the interaction between RadGrid and RadWindow with the data transfer.
SOLUTION
The forthcoming code implementation presents how to fetch the data from the checked records in the grid which resides in a modal RadWindow object. The main parts of the logic are outlined in the points below:
- Wire the OnCheckedChanged event of the checkbox residing in the template grid column
- Insert the data for the selected grid records in a Stack object and store it in a Session variable (you may also prefer to use different technique to preserve the info for the selected items)
- Assign function to the OnClientClick attribute of the button shown under the grid which closes the window instance and reloads the parent page. The data from the selected records will be rendered in a label control on the main page.
Those are the code snippets from the sample application attached at the end of this knowledge base article:
Default.aspx
| <asp:ScriptManager ID="ScriptManager1" runat="server" /> |
| |
| <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
| <script type="text/javascript"> |
| function ShowDialog() |
| { |
| window.radopen(null, "UserListDialog"); |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| |
| <input id="Button1" type="button" value="Open grid window" onclick="ShowDialog()" /> |
| |
| <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Overlay="false"> |
| <Windows> |
| <telerik:RadWindow ID="UserListDialog" runat="server" Width="600px" Height="600px" Modal="true" |
| Title="User List Dialog" NavigateUrl="SelectionList.aspx"></telerik:RadWindow> |
| </Windows> |
| </telerik:RadWindowManager> |
| <br /> |
| <asp:Label ID="Label1" runat="server"></asp:Label> |
Default.aspx.cs
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (Session["returnedValues"] != null) |
| { |
| Stack results = (Stack)Session["returnedValues"]; |
| while (results.Count > 0) |
| { |
| Label1.Text += results.Pop(); |
| } |
| } |
| } |
Default.aspx.vb
| Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) |
| If Not Session("returnedValues") is Nothing Then |
| Dim results As Stack = DirectCast(Session("returnedValues"), Stack) |
| While results.Count > 0 |
| Label1.Text += results.Pop() |
| End While |
| End If |
| End Sub |
SelectionList.aspx
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| |
| <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
| <script type="text/javascript"> |
| function GetRadWindow() |
| { |
| var oWindow = null; |
| if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog |
| else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well) |
| |
| return oWindow; |
| } |
| function CloseAndReload() |
| { |
| var oWnd = GetRadWindow(); |
| oWnd.BrowserWindow.location.reload(); |
| oWnd.close(); |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadGrid1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="AccessDataSource1" GridLines="None" Width="95%"> |
| <ExportSettings> |
| <Pdf FontType="Subset" PaperSize="Letter" /> |
| <Excel Format="Html" /> |
| <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /> |
| </ExportSettings> |
| <MasterTableView CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" |
| DataSourceID="AccessDataSource1" Dir="LTR" Frame="Border" TableLayout="Auto"> |
| <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" |
| Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" |
| Resizable="False" Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <EditFormSettings> |
| <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"> |
| </EditColumn> |
| </EditFormSettings> |
| <Columns> |
| <telerik:GridTemplateColumn> |
| <ItemTemplate> |
| <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| <asp:Button ID="btnGetValues" Text="Get selected and close" runat="server" OnClientClick="CloseAndReload();"> |
| </asp:Button> |
| <asp:AccessDataSource ID="AccessDataSource1" DataFile="~/App_Data/Nwind.mdb" |
| SelectCommand="SELECT TOP 10 CustomerID, ContactName, ContactTitle FROM Customers" |
| runat="server"> |
| </asp:AccessDataSource> |
| |
SelectionList.aspx.cs
| protected Stack returnedValues = new Stack(); |
| |
| protected void CheckBox1_CheckedChanged(object sender, EventArgs e) |
| { |
| if (Session["returnedValues"] != null) |
| { |
| returnedValues = (Stack)Session["returnedValues"]; |
| } |
| GridDataItem dataItem = (GridDataItem)(sender as CheckBox).NamingContainer; |
| string selectedCustomer = "<b>Selected customer data:</b> " + dataItem["CustomerID"].Text + " : " + dataItem["ContactName"].Text + " : " + dataItem["ContactTitle"].Text + "<br/>"; |
| |
| returnedValues.Push(selectedCustomer); |
| Session["returnedValues"] = returnedValues; |
| } |
SelectionList.aspx.vb
| Protected returnedValues As New Stack() |
| |
| Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) |
| If Session("returnedValues") <> Nothing Then |
| returnedValues = DirectCast(Session("returnedValues"), Stack) |
| End If |
| Dim dataItem As GridDataItem = DirectCast((TryCast(sender, CheckBox)).NamingContainer, GridDataItem) |
| Dim selectedCustomer As String = "<b>Selected customer data:</b> " + dataItem("CustomerID").Text + " : " + dataItem("ContactName").Text + " : " + dataItem("ContactTitle").Text + "<br/>" |
| |
| returnedValues.Push(selectedCustomer) |
| Session("returnedValues") = returnedValues |
| End Sub |
SOLUTION
The forthcoming code implementation presents how to fetch the data from the checked records in the grid which resides in a modal RadWindow object. The main parts of the logic are outlined in the points below:
- Wire the OnCheckedChanged event of the checkbox residing in the template grid column
- Insert the data for the selected grid records in a Stack object and store it in a Session variable (you may also prefer to use different technique to preserve the info for the selected items)
- Assign function to the OnClientClick attribute of the button shown under the grid which closes the window instance and reloads the parent page. The data from the selected records will be rendered in a label control on the main page.
Those are the code snippets from the sample application attached at the end of this knowledge base article:
Default.aspx
| <script type="text/javascript"> |
| function ShowDialog() |
| { |
| window.radopen(null, "UserListDialog"); |
| } |
| </script> |
| |
| <input id="Button1" type="button" value="Open grid window" onclick="ShowDialog()" /> |
| <radW:RadWindowManager ID="RadWindowManager1" runat="server" Overlay="false"> |
| <Windows> |
| <radW:RadWindow ID="UserListDialog" runat="server" Width="600px" Height="600px" Modal="true" |
| Title="User List Dialog" NavigateUrl="SelectionList.aspx" /> |
| </Windows> |
| </radW:RadWindowManager> |
| <br /> |
| <asp:Label ID="Label1" runat="server"></asp:Label> |
Default.aspx.cs
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (Session["returnedValues"] != null) |
| { |
| Stack results = (Stack)Session["returnedValues"]; |
| while (results.Count > 0) |
| { |
| Label1.Text += results.Pop(); |
| } |
| } |
| } |
Default.aspx.vb
| Protected Sub Page_Load(ByVal sender as Object, ByVal e as EventArgs) Handles MyBase.Load |
| If Not Session("returnedValues") is Nothing Then |
| Dim results as Stack = CType(Session("returnedValues"), Stack) |
| |
| While results.Count > 0 |
| Label1.Text += results.Pop() |
| End While |
| End If |
| End Sub |
SelectionList.aspx
| <script type="text/javascript"> |
| function GetRadWindow() |
| { |
| var oWindow = null; |
| if (window.RadWindow) oWindow = window.RadWindow; //Will work in Moz in all cases, including clasic dialog |
| else if (window.frameElement.RadWindow) oWindow = window.frameElement.RadWindow;//IE (and Moz az well) |
| |
| return oWindow; |
| } |
| function CloseAndReload() |
| { |
| var oWnd = GetRadWindow(); |
| oWnd.BrowserWindow.location.reload(); |
| oWnd.Close(); |
| } |
| </script> |
| <radG:RadGrid ID="RadGrid1" DataSourceID="AccessDataSource1" runat="server" Width="95%" |
| EnableAJAX="true"> |
| <MasterTableView Width="100%" DataSourceID="AccessDataSource1"> |
| <Columns> |
| <radG:GridTemplateColumn HeaderText="Check/Uncheck" UniqueName="TemplateColumn"> |
| <ItemTemplate> |
| <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" /> |
| </ItemTemplate> |
| </radG:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings> |
| </ClientSettings> |
| </radG:RadGrid> |
| <asp:Button ID="btnGetValues" Text="Get selected and close" runat="server" OnClientClick="CloseAndReload();"> |
| </asp:Button> |
| <br /> |
| <asp:AccessDataSource ID="AccessDataSource1" DataFile="~/Grid/Data/Access/Nwind.mdb" |
| SelectCommand="SELECT TOP 10 CustomerID, ContactName, ContactTitle FROM Customers" |
| runat="server"></asp:AccessDataSource> |
SelectionList.aspx.cs
| protected Stack returnedValues = new Stack(); |
| |
| protected void CheckBox1_CheckedChanged(object sender, EventArgs e) |
| { |
| if (Session["returnedValues"] != null) |
| { |
| returnedValues = (Stack)Session["returnedValues"]; |
| } |
| GridDataItem dataItem = (GridDataItem)(sender as CheckBox).NamingContainer; |
| string selectedCustomer = "<b>Selected customer data:</b> " + dataItem["CustomerID"].Text + " : " + dataItem["ContactName"].Text + " : " + dataItem["ContactTitle"].Text + "<br/>"; |
| |
| returnedValues.Push(selectedCustomer); |
| Session["returnedValues"] = returnedValues; |
| } |
SelectionList.aspx.vb
| Protected returnedValues As New Stack() |
| |
| Protected Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) |
| If Not Session("returnedValues") Is Nothing Then |
| returnedValues = CType(Session("returnedValues"), Stack) |
| End If |
| |
| Dim dataItem As GridDataItem = CType(sender, CheckBox).NamingContainer |
| Dim selectedCustomer As String = "<b>Selected customer data:</b> " & dataItem("CustomerID").Text & " : " & dataItem("ContactName").Text & " : " & dataItem("ContactTitle").Text & "<br/>" |
| |
| returnedValues.Push(selectedCustomer) |
| Session("returnedValues") = returnedValues |
| End Sub 'CheckBox1_CheckedChanged |
Please
Sign In
to rate this article.