Dec 12, 2013, 7:44 AM
[CLOSED] How to View and Get Dynamically loaded user controls
Hi all,
We are working on the following requirement,
In a user control we have a gridpanel. In a page we are loading that user control many times and assigning data to each user control's store.
Here my issues are
1. with the following code we are unable to view the gridpanels
2. How to get/find dynamically created gridpanels from code behind?
3. How can we find the selected rows from each gridpanel ?
Here is the sample code to reproduce the issue,
Aspx code
========
================
===================
Thank you
Mohan
We are working on the following requirement,
In a user control we have a gridpanel. In a page we are loading that user control many times and assigning data to each user control's store.
Here my issues are
1. with the following code we are unable to view the gridpanels
2. How to get/find dynamically created gridpanels from code behind?
3. How can we find the selected rows from each gridpanel ?
Here is the sample code to reproduce the issue,
Aspx code
========
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicUserControls.aspx.cs"
Inherits="DynamicUserControls" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="GridUserControl.ascx" TagPrefix="ucg" TagName="ucGrid" %>
<!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>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLoad_Click(object sender, DirectEventArgs e)
{
BindControls();
panelExceptions.Show();
}
private void BindControls()
{
int Index = 4;
for (int i = 1; i <= Index; i++)
{
Ext.Net.Panel p1 = new Ext.Net.Panel();
p1.ID = "pnl" + i;
GridUserControl ucGrid = (GridUserControl)this.Page.LoadControl("GridUserControl.ascx");
ucGrid.ID = "G" + i;
ucGrid.AssignTitle("G" + i);
p1.ContentContainer.Controls.Add(ucGrid);
panelExceptions.Items.Add(p1);
}
}
protected void btnGet_Click(object sender, DirectEventArgs e)
{
findControls(this.Controls);
}
private void findControls(System.Web.UI.ControlCollection ctrl)
{
foreach (Control ct in ctrl)
{
if (ct is GridUserControl)
{
//SectionControls.Add(ctrl);
}
if (ct.Controls.Count > 0)
{
findControls(ct.Controls);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager runat="server" />
<ext:Panel ID="panelExceptions" runat="server" Width="385" Height="700" AutoScroll="true"
Hidden="true">
</ext:Panel>
<ext:Button ID="btnLoad" runat="server" Text="Load Grids">
<DirectEvents>
<Click OnEvent="btnLoad_Click">
</Click>
</DirectEvents>
</ext:Button>
<br />
<br />
<ext:Button ID="btnGet" runat="server" Text="Get Grid Data">
<DirectEvents>
<Click OnEvent="btnGet_Click">
</Click>
</DirectEvents>
</ext:Button>
</div>
</form>
</body>
</html>
UserControl Source Code================
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="GridUserControl.ascx.cs"
Inherits="GridUserControl" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:Store ID="StoreHazardsGrid" runat="server" meta:resourcekey="StoreHazardsGridResource1">
<Model>
<ext:Model ID="mdlStoreHazardsGrid" runat="server" IDProperty="HazardID">
<Fields>
<ext:ModelField Name="Id" Type="Int">
</ext:ModelField>
<ext:ModelField Name="Name" Type="String">
</ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
<ext:GridPanel ID="HazardsGridControl" runat="server" Title="Hazards List" Border="true"
AutoScroll="true" meta:resourcekey="HazardsGridControlResource2" StoreID="StoreHazardsGrid"
ButtonAlign="Left" Layout="FitLayout" Height="300px" Width="400px">
<ColumnModel>
<Columns>
<ext:Column ID="Column2" runat="server" DataIndex="Name" Text="Name" Flex="1">
</ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
UserControl CodeBehind code===================
protected void Page_Load(object sender, EventArgs e)
{
}
public void AssignTitle(string step)
{
HazardsGridControl.Title = step;
StoreHazardsGrid.DataSource = this.Data;
StoreHazardsGrid.DataBind();
}
private object[] Data
{
get
{
return new object[]
{
new object[] { 10,"3m Co" },
new object[] { 20,"Alcoa Inc"},
new object[] { 30,"Altria Group Inc"}
};
}
}
Please contact if you need more explanationThank you
Mohan
Last edited by Daniil; Dec 24, 2013 at 8:29 AM.
Reason: [CLOSED]