473,221 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

DataList in a composite control. ItemCommand not firing.

Hi there,

I am using a DataList in a composite control.

The DataList has an Custom ItemTemplate(ITemplate) which adds a Button
to the DataList Item as shown in the code below :

public class DatalistItemTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
Button B = new Button();

B.DataBinding += new EventHandler(B_DataBinding);

container.Controls.Add(B);
}
private void B_DataBinding(object sender, EventArgs e)
{
Button btn = (Button)sender;

DataListItem container = (DataListItem)btn.NamingContainer ;

btn.ID = "Button" +
Convert.ToString(DataBinder.Eval(((DataListItem)co ntainer).DataItem,
"Item"));
btn.Text =
Convert.ToString(DataBinder.Eval(((DataListItem)co ntainer).DataItem,
"Item"));
btn.CommandArgument =
Convert.ToString(DataBinder.Eval(((DataListItem)co ntainer).DataItem,
"Item"));
btn.CommandName = "Select";
}
}

The Custom ItemTemplate is assigned and then the databind is executed
using the following code :

this.DataList1.RepeatColumns = this.ArrayListDisplayedTabs.Count;
this.DataList1.RepeatDirection = RepeatDirection.Horizontal;
DataList1.ItemTemplate = new DatalistItemTemplate();

this.DataList1.DataSource = this.ArrayListData ;
this.DataList1.DataBind();

The ArrayListData which the datalist is bound to contains the following
type of data

[Serializable()]
public class TabItem
{
string StringItem;

public TabItem(string ItemName)
{
this.StringItem = ItemName;
}

public string Item
{
get { return StringItem; }
}
}

THE BUTTONS ARE BEING PROPERLY DISPLAYED.

The ItemCommand is attached to the DataList in the OnInit Override of
the Control just like all the other events.

this.DataList1.ItemCommand += new
DataListCommandEventHandler(DataList1_ItemCommand) ;

When a button in the DataList is clicked, the ItemCommand should be
fired. This is not happening.

The same DataList when used in a User Control fires the ItemCommand
event properly. However, when used in a Composite Control the event
does not fire.

Any suggestions..

Thanks...

Shawn..

Jul 24 '06 #1
1 3932
Hi,

if you databind DataList every time you add it to Controls collection, that
could "eat" up the events. Do initial databinding inside if !Page.IsPostBack
or optionally in overridden dataBind method, so that dataBind of UC should
be called to get dataList databound.

-
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

<sh***********@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hi there,

I am using a DataList in a composite control.

The DataList has an Custom ItemTemplate(ITemplate) which adds a Button
to the DataList Item as shown in the code below :

public class DatalistItemTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
Button B = new Button();

B.DataBinding += new EventHandler(B_DataBinding);

container.Controls.Add(B);
}
private void B_DataBinding(object sender, EventArgs e)
{
Button btn = (Button)sender;

DataListItem container = (DataListItem)btn.NamingContainer ;

btn.ID = "Button" +
Convert.ToString(DataBinder.Eval(((DataListItem)co ntainer).DataItem,
"Item"));
btn.Text =
Convert.ToString(DataBinder.Eval(((DataListItem)co ntainer).DataItem,
"Item"));
btn.CommandArgument =
Convert.ToString(DataBinder.Eval(((DataListItem)co ntainer).DataItem,
"Item"));
btn.CommandName = "Select";
}
}

The Custom ItemTemplate is assigned and then the databind is executed
using the following code :

this.DataList1.RepeatColumns = this.ArrayListDisplayedTabs.Count;
this.DataList1.RepeatDirection = RepeatDirection.Horizontal;
DataList1.ItemTemplate = new DatalistItemTemplate();

this.DataList1.DataSource = this.ArrayListData ;
this.DataList1.DataBind();

The ArrayListData which the datalist is bound to contains the following
type of data

[Serializable()]
public class TabItem
{
string StringItem;

public TabItem(string ItemName)
{
this.StringItem = ItemName;
}

public string Item
{
get { return StringItem; }
}
}

THE BUTTONS ARE BEING PROPERLY DISPLAYED.

The ItemCommand is attached to the DataList in the OnInit Override of
the Control just like all the other events.

this.DataList1.ItemCommand += new
DataListCommandEventHandler(DataList1_ItemCommand) ;

When a button in the DataList is clicked, the ItemCommand should be
fired. This is not happening.

The same DataList when used in a User Control fires the ItemCommand
event properly. However, when used in a Composite Control the event
does not fire.

Any suggestions..

Thanks...

Shawn..

Jul 24 '06 #2

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

Similar topics

3
by: Kenneth | last post by:
Hi there, The OnItemCommand in my datalist is acting very weirdly, the first time the page is loaded(or anything on the datalist is clicked for the first time) its firing only once, but after...
2
by: Jim Heavey | last post by:
I have a datalist control and when edit mode, I have three buttons, one for delete, one for cancel and one for Update. My Update button is not causing anything to happen. The other two events...
3
by: Chris | last post by:
Hi Folks, well I have this "small" problem with the footertemplate in a datalist. I added a button and a textbox to update the db with the given String of the Textbox. I already searched for...
3
by: Patrick Olurotimi Ige | last post by:
Can i have a Button in a Datalist? The button is for posting a form to the the Database FOr example:- <ASP:DataList id="heading0" RepeatLayout="Flow" RepeatDirection="Horizontal" ...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
1
by: Gary | last post by:
I'm having a problem with the DataList control, my situation is as follows... I have a DataList with a Drop Down List Box (DDLB) in the header, this DDLB is set to AutoPostBack = True. When the...
1
by: Nathan Sokalski | last post by:
I have a custom Control that I have made that contains a DataList. In either the ItemCommand or SelectedIndexChanged event I need to retrieve a value from the DataItem of the SelectedItem. I have...
1
by: berny.zamora | last post by:
Hello everyone, I have a composite control (lets call it the parent) that contains a datalist. The datalist has an ItemTemplate that contains another composite control (lets call it the child)....
1
by: rajkumarbathula | last post by:
Hi I am struckup with a big issue. ie., On my Page i am rendering 2 dynamic datalists each has dynamic link buttons. my problem is: i am not able to handle ItemCommandEvent of both the...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.