Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataList doesn't fire events

Reply
Thread Tools

DataList doesn't fire events

 
 
Neil Jarman
Guest
Posts: n/a
 
      08-17-2005
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" %>
<MMataSet
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></MMataSet>
<MMageBind 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>


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      08-20-2005
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" <> wrote in message
news:ddvss2$pfq$1$...
> 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" %>
> <MMataSet
> 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></MMataSet>
> <MMageBind 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>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Events in DataList EditItem Template won't fire Crazy Cat ASP .Net 3 10-14-2008 01:17 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
DataList doesn't fire events Neil Jarman ASP .Net 1 08-20-2005 04:26 PM
On fighting fire with fire... skip@pobox.com Python 16 08-01-2005 07:09 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM



Advertisments