468,554 Members | 1,889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

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 1941
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by V. Jenks | last post: by
2 posts views Thread by Jim Heavey | last post: by
10 posts views Thread by Bharat | last post: by
4 posts views Thread by Patrick.O.Ige | last post: by
1 post views Thread by Jim Heavey | last post: by
1 post views Thread by Pavan | last post: by
1 post views Thread by shantanu_kush | last post: by
3 posts views Thread by Crazy Cat | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.