473,396 Members | 2,099 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,396 software developers and data experts.

DataList doesn't fire events

Hi,

I'm new to this today, and I've got some test code (see below.) The data
loads fine.

I can't understand why any of the events fire. Once the page loads, clicking
on thew button from the ItemTemplate does not fire the OnItemCommand event.
It just fires a page reload - as a postback.

I guess I'm missing something really obvious and important here?

Any help greatfully received,

Cheers,

NEIL


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1"
Debug="true" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"
Assembly="DreamweaverCtrls,version=1.0.0.0,publicK eyToken=836f606ede05d46a,c
ulture=neutral" %>
<MM:DataSet
id="DataSet1"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_STRING
_SBC_SQL") %>'
DatabaseType='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_DATABA
SETYPE_SBC_SQL") %>'
CommandText='<%# "SELECT iContactID, sPostCode, dDateCreated, sFamilyName,
sEmailAddress FROM tblTivyContactList WHERE (sPostCode LIKE " + Chr(39) +
"YO11%" + Chr(39) + ") ORDER BY dDateCreated DESC" %>'
Debug="true"
<EditOps><EditOpsTable Name="" />

<Parameter Name="iContactID" Type="VarChar" />
<Parameter Name="sFamilyName" Type="VarChar" />
<Parameter Name="sEmailAddress" Type="VarChar" />
<Parameter Name="" Type="BigInt" IsPrimary="true" />
</EditOps></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="Visitors/TivyInternal.css" rel="stylesheet" type="text/css" />
</head>
<body>
Message: <asp:label id="lblMessage" runat="server" />
<form runat="server">

<asp:datalist ID="aspDL" runat="server"
DataSource="<%# DataSet1.DefaultView %>"
DataKeyField="iContactID"
RepeatLayout="Flow"
OnItemCommand="DoItemSelect"
OnEditCommand="DoItemEdit"
OnUpdateCommand="DoItemUpdate"
OnDeleteCommand="DoItemDelete"
OnCancelCommand="DoItemCancel"
autogeneratecolumns="false">

<HeaderTemplate>
List of contacts in YO11
</HeaderTemplate>

<ItemTemplate>
<asp:Button CommandName="Select" Text="Select" runat="server" />
PostCode: <b><%# DataSet1.FieldValue("sPostCode", Container) %></b>
</ItemTemplate>

<SelectedItemTemplate>
<asp:Button CommandName="Edit" Text="Edit" runat="server" />
PostCode: <b><%# Container.DataItem("sPostCode") %></b><br />
SurName: <%# DataSet1.FieldValue("sFamilyName", Container) %> &nbsp;
Email: <%# DataSet1.FieldValue("sEmailAddress", Container) %><br />
</SelectedItemTemplate>

<EditItemTemplate>
<asp:Button CommandName="Update" Text="Update" runat="server" />
<asp:Button CommandName="Delete" Text="Delete" runat="server" />
<asp:Button CommandName="Cancel" Text="Cancel" runat="server" />
PostCode: <b><%# Container.DataItem("sPostCode") %></b><br />
Surname: <asp:textbox id="txtSurname" Text="<%#
DataSet1.FieldValue("sFamilyName", Container) %>"> &nbsp;
Email: <asp:textbox id="txtEmail" Text="<%#
DataSet1.FieldValue("sEmailAddress", Container) %>"><br />
</EditItemTemplate>

</asp:datalist>
</form>
<!--------------------------------------------------------------------------
->
<script language="vb" runat="server">

Sub Page_Load()
if not page.ispostback then
lblMessage.text = now()
aspDL.DataBind()
else
'aspDL.selectedindex = 7 'test
'aspDL.DataBind()
end if
End Sub

Sub DoItemSelect(objSource As object, objArgs As DataListCommandEventArgs)
lblMessage.text = "in DoItemInfo"
if objArgs.CommandName = "Select" then
lblMessage.text = "In DoItemInfo"
aspDL.selectedindex = objArgs.item.itemindex
aspDL.DataBind()
end if
End Sub

sub DoItemEdit(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemEdit"
aspDL.selectedindex = -1
aspDL.EditItemIndex = objArgs.item.itemindex
aspDL.DataBind()
end sub

sub DoItemUpdate(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemUpdate"
end sub

sub DoItemDelete(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemDelete"
end sub

sub DoItemCancel(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemCancel"
end sub
</script>

<!--------------------------------------------------------------------------
->
</body>
</html>
Nov 19 '05 #1
1 2128
Hi,

have you made sure you don't databind the dataList on every postback in
Page_Load? E.g do you have binding inside If Not Page.IsPostBack check (
if(!Page.IsPostBack){...} in C# )

If you rebind the DataList (or any databound control) accidentally in
Page_Load on every request that will "clear" the events to be raised and
cause them not to be raised.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Neil Jarman" <ne**@tNOiSPAMvPLEASEy.co.uk> wrote in message
news:dd*******************@news.demon.co.uk...
Hi,

I'm new to this today, and I've got some test code (see below.) The data
loads fine.

I can't understand why any of the events fire. Once the page loads, clicking on thew button from the ItemTemplate does not fire the OnItemCommand event. It just fires a page reload - as a postback.

I guess I'm missing something really obvious and important here?

Any help greatfully received,

Cheers,

NEIL


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"
Assembly="DreamweaverCtrls,version=1.0.0.0,publicK eyToken=836f606ede05d46a,c ulture=neutral" %>
<MM:DataSet
id="DataSet1"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_STRING _SBC_SQL") %>'
DatabaseType='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_DATABA SETYPE_SBC_SQL") %>'
CommandText='<%# "SELECT iContactID, sPostCode, dDateCreated, sFamilyName,
sEmailAddress FROM tblTivyContactList WHERE (sPostCode LIKE " + Chr(39) +
"YO11%" + Chr(39) + ") ORDER BY dDateCreated DESC" %>'
Debug="true"
<EditOps><EditOpsTable Name="" /> <Parameter Name="iContactID" Type="VarChar" />
<Parameter Name="sFamilyName" Type="VarChar" />
<Parameter Name="sEmailAddress" Type="VarChar" />
<Parameter Name="" Type="BigInt" IsPrimary="true" />
</EditOps></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="Visitors/TivyInternal.css" rel="stylesheet" type="text/css" />
</head>
<body>
Message: <asp:label id="lblMessage" runat="server" />
<form runat="server">

<asp:datalist ID="aspDL" runat="server"
DataSource="<%# DataSet1.DefaultView %>"
DataKeyField="iContactID"
RepeatLayout="Flow"
OnItemCommand="DoItemSelect"
OnEditCommand="DoItemEdit"
OnUpdateCommand="DoItemUpdate"
OnDeleteCommand="DoItemDelete"
OnCancelCommand="DoItemCancel"
autogeneratecolumns="false">

<HeaderTemplate>
List of contacts in YO11
</HeaderTemplate>

<ItemTemplate>
<asp:Button CommandName="Select" Text="Select" runat="server" />
PostCode: <b><%# DataSet1.FieldValue("sPostCode", Container) %></b>
</ItemTemplate>

<SelectedItemTemplate>
<asp:Button CommandName="Edit" Text="Edit" runat="server" />
PostCode: <b><%# Container.DataItem("sPostCode") %></b><br />
SurName: <%# DataSet1.FieldValue("sFamilyName", Container) %>

&nbsp; Email: <%# DataSet1.FieldValue("sEmailAddress", Container) %><br />
</SelectedItemTemplate>

<EditItemTemplate>
<asp:Button CommandName="Update" Text="Update" runat="server" />
<asp:Button CommandName="Delete" Text="Delete" runat="server" />
<asp:Button CommandName="Cancel" Text="Cancel" runat="server" />
PostCode: <b><%# Container.DataItem("sPostCode") %></b><br />
Surname: <asp:textbox id="txtSurname" Text="<%#
DataSet1.FieldValue("sFamilyName", Container) %>"> &nbsp;
Email: <asp:textbox id="txtEmail" Text="<%#
DataSet1.FieldValue("sEmailAddress", Container) %>"><br />
</EditItemTemplate>

</asp:datalist>
</form>
<!-------------------------------------------------------------------------- ->
<script language="vb" runat="server">

Sub Page_Load()
if not page.ispostback then
lblMessage.text = now()
aspDL.DataBind()
else
'aspDL.selectedindex = 7 'test
'aspDL.DataBind()
end if
End Sub

Sub DoItemSelect(objSource As object, objArgs As DataListCommandEventArgs)
lblMessage.text = "in DoItemInfo"
if objArgs.CommandName = "Select" then
lblMessage.text = "In DoItemInfo"
aspDL.selectedindex = objArgs.item.itemindex
aspDL.DataBind()
end if
End Sub

sub DoItemEdit(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemEdit"
aspDL.selectedindex = -1
aspDL.EditItemIndex = objArgs.item.itemindex
aspDL.DataBind()
end sub

sub DoItemUpdate(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemUpdate"
end sub

sub DoItemDelete(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemDelete"
end sub

sub DoItemCancel(objSource as object, objArgs as DataListCommandEventArgs)
lblMessage.text = "in DoItemCancel"
end sub
</script>

<!-------------------------------------------------------------------------- ->
</body>
</html>

Nov 19 '05 #2

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

Similar topics

4
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a...
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...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
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: Jim Heavey | last post by:
First time trying to use the Datalist and I can not seem to get the events to fire. I set up my Data List control and I identify the event for the "OnEditCommand". I also set up an...
1
by: Pavan | last post by:
Hi All, I have created a custom DataList web custom control, which populates data from a dataset. This dataset is available at runtime and exposed as property by my custom control. During...
1
by: shantanu_kush | last post by:
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...
3
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...
7
by: rajkumarbathula | last post by:
Hi All This is my first query in this site. firstly i like to appreciate all the contributors of this site and solutions. I am having an issue while using DataList dynamically. I am able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.