473,854 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to load a template into datalist at runtime?

Isz
PROBLEM:
This problem is related to the postback and handling events correctly.
BACKGROUND:
I have a datalist which acts as a tabbes list with horizontal layout.
This datalist is bound to a strogly typed collection I called
TabCollection which is a collevtion of items called tab. Each tab is as
follows:

tab.TabName
tab.TabTemplate
tab.TabIndex

TabTemplate is a string which holds the location of a user control which
inherits from ITemplate. Ideally, each tab instance within
TabCollection would contain a reference to a different template such
that when a user clicks on any of the horizontally aligned tabs, the
datalist would load the corresponding template. Each template is a user
control (.ascx) and contains an assortment of server controls such as
the dropdownlist, listbox, button, texbox, etc.

BEHAVIOR:
on Page_Load I am successfully able to load each template, as it is
defined by the instance of tab, int the item selected as the
SelectedItemTem plate. While the page looks nice, and all controls are
visible, invoking any of them that depend upon a postback results in one
of several tested outcomes:

1. The template disappears - this occurs if I select an item is the
drop-down list but do not bubble its event up to the page containing the
datalist.

2. The dropdown lists contents are reset upon a selection - this occurs
if I do bubble the selectedIndeCha nged event up to the page with the
datalist and call ReBind(). The selected template remains visible.
QUESTION:
How is it handled that a datalist's SelectedItemTem plate loaded template
is retained while also being able to appropriately use controls within
the custom template?

CODE:
Though there might be a bit of code posted here, it might be useful for
some even in its current broken state.

+++++++++++++++ +++++++++++++++ +++++++++++++
Tabs.ascx - this file contains the datalist

private void Page_Load(objec t sender, System.EventArg s e)
{
if(!Page.IsPost Back)
{
dl_tabs.Selecte dIndex = INTIALIZE_TAB_I NDEX;
BindData();
}
}

public void BindData()
{
dl_tabs.DataSou rce = tabsList;
dl_tabs.DataKey Field = "TabIndex";
dl_tabs.DataBin d();
}

private void dl_tabs_ItemDat aBound(object sender, DataListItemEve ntArgs
e)
{

if(e.Item.ItemT ype == ListItemType.Se lectedItem)
{
int tabId = (int)dl_tabs.Da taKeys[e.Item.ItemInde x];
MyNameSpace.Web .Controls.Templ ates.ITemplate template =
(MyNameSpace.We b.Controls.Temp lates.ITemplate )LoadControl(Ta bsList
[e.Item.ItemInde x].TabTemplate);
template.Course CategoryIndexCh anged += new
CommandEventHan dler(template_C ourseCategoryIn dexChanged);
template.Course LevelIndexChang ed += new CommandEventHan dler
(template_Cours eLevelIndexChan ged);
panel_selectedT ab.Controls.Add ((System.Web.UI .UserControl)
template);
if(panel_select edTab.Controls. Count > 1)
panel_selectedT ab.Controls.Rem oveAt(0);
}
}

private void dl_tabs_ItemCom mand(object source, DataListCommand EventArgs
e)
{
dl_tabs.Selecte dIndex = e.Item.ItemInde x;
BindData();
}

+++++++++++++++ +++++++++++++++ +++++++++++++
+++++++++++++++ +++++++++++++++ +++++++++++++
MyTemplate1.asc x - this file is a user control template that gets loaded
in the dl_tabs_ItemDat aBound of the Tabs.ascx datalist event.

// Events
public event CommandEventHan dler CourseCategoryI ndexChanged;

private void Page_Load(objec t sender, System.EventArg s e)
{
BindData();
}

public void BindData()
{
// DropDown Lists
MyNameSpace.Dat aEntities.Colle ctionClasses.Co urseCategoryCol lectio
n courseCategoryC ollection = new CourseCategoryC ollection();
courseCategoryC ollection = FacultyCourseSe rver.GetCourseC ategories
(FacultyCourseS erver.DEFAULT_F ACULTY_ID);
this.ddl_course Category.DataSo urce = courseCategoryC ollection;
this.ddl_course Category.DataTe xtField = EntityFieldFact ory.Create
(CourseCategory FieldIndex.Cour seName).Name;
this.ddl_course Category.DataVa lueField = EntityFieldFact ory.Create
(CourseCategory FieldIndex.Cour seCategoryId).N ame;
this.ddl_course Category.DataBi nd();
}

private void ddl_courseCateg ory_SelectedInd exChanged(objec t sender,
System.EventArg s e)
{
// Do stuff like bubble up event.
if(CourseCatego ryIndexChanged != null)
{
CommandEventArg s ev = new CommandEventArg s(null,
ddl_courseCateg ory.SelectedInd ex);
CourseCategoryI ndexChanged(thi s, ev);
}

}
+++++++++++++++ +++++++++++++++ +++++++++++++
If anyone can tackle thi, please feel free to ask if more code is needed
or additional information.

Thank you.
Dec 29 '05 #1
0 3953

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1126
by: Fabrizio | last post by:
Hi, I'm using a datalist with a LoadTemplate method from an ascx(text format) file. Everything is working fine till i need to find a control within the datalist in the datalist_itemdatabound event. I create on the template a label named "LABEL1" e when i try to use DataList.findcontrol , it can't find it. Any suggestion? Thank you, Fabrizio
9
21653
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
0
1004
by: Barry | last post by:
Hi, I have a template in a DataList. The template also contains a DataList. I'd like to bubble the OnItemCommand event from the template's DataList up the hierarchy. Here's what I've tried so far: In the container: Protected Overrides Function OnBubbleEvent(ByVal source As Object, ByVal e As EventArgs) As Boolean Trace.Warn(source.ToString)
8
4287
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this...
3
2764
by: moondaddy | last post by:
using vb.net 1.1 I have a datalist and in it's item template I have 2 buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it opens up the edit template as it works with the edit command. But the how do I wire ShipToThisAddress button? Its going to submit the address ID to the database and do a redirect to another page. In the process of doing this, it will need to get the row index in the datalist so I can get the...
1
2186
by: DotNetJunkies User | last post by:
Hi, I was wondering if it is possible to load datagrid into datalist programatically using ITemplate interface with the following structure and place intp placeholder control. PlaceHolder - DataList - DataGrid (DataList Item) I have hierarchical data that I want to display using webcontrols whilst calculating minimum cost for each courier with Compute() method in DataGrid.
0
1128
by: Richard Steele | last post by:
I have a default page that I load usercontrols depending on requirements through a master template using a PlaceHolder i.e. //some logic here..... Control UCUsers = LoadControl("../UserControls/users.ascx"); PlaceHolderUC.Controls.Add(UCUsers ); the datalist control (ascx) loads correctly but when I try click the datalist template image button i.e. <ItemTemplate>
1
1718
by: Benton | last post by:
Hi there, I have a HyperLink control inside a DataList's ItemTemplate: <asp:DataList ID="lstDatos" runat="server"> <ItemTemplate> <asp:HyperLink ID="lnkName" runat="server" CssClass="Link" Text='<% #Eval("NAME") %>' NavigateUrl="repInTransitByProvider.aspx?id=<% #Eval('ID') %>"> </asp:HyperLink>
3
2816
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I need to control the visibility of a textbox based on a dropdown selection in the datalist's edititem template. To do this, I registered a client script block function and attached a client side handler for the dropdownlist's onchange event in the...
0
9899
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9750
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10672
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10362
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9510
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4149
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.