DataList doesn't fire events

N

Neil Jarman

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,publicKeyToken=836f606ede05d46a,c
ulture=neutral" %>
<MM:DataSet
id="DataSet1"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%#
System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING
_SBC_SQL") %>'
DatabaseType='<%#
System.Configuration.ConfigurationSettings.AppSettings("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>
 
T

Teemu Keiski

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top