Datalist EditItemTemplate does not fire up: Please help; ASP.Net - very urgent
The following code does not fire-up EditItemTemplate. Could someone spot the error for me, please?
<%@ page language="vb" %>
<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient" %>
<script runat="server">
sub page_load( obj as object, e as eventargs)
dim con as sqlconnection=new sqlconnection("data source=(local);initial catalog=classNorthwind; integrated security=sspi;")
dim cmd as new sqlDataAdapter("select * from employees",con)
dim ds as dataset =new dataset
cmd.fill(ds,"customers")
dl.datasource=ds
dl.databind()
end sub
Sub dl_ItemCommand(obj as object, e as DataListCommandEventArgs)
dl.SelectedIndex=e.Item.ItemIndex
dl.databind
end sub
Sub dl_EditCommand(obj as object, e as DataListCommandEventArgs)
dl.SelectedIndex=e.Item.ItemIndex
dl.databind
end sub
Sub dl_CancelCommand(obj as object, e as DataListCommandEventArgs)
dl.SelectedIndex=-1
dl.databind
end sub
Sub dl_UpdateCommand(obj as object, e as DataListCommandEventArgs)
dl.databind
end sub
Sub dl_DeleteCommand(obj as object, e as DataListCommandEventArgs)
dl.databind
end sub
</script>
<html>
<head></head>
<body style="text-align:center;">
<Form runat="server">
<asp:datalist id="dl" runat="server" repeatlayout="table" repeatdirection="vertical" repeatcolumns ="1" datakeyfield="EmployeeID"
SelectedItemStyle-BackColor="#CCCC99" OnItemCommand="dl_ItemCommand" OnEditCommand="dl_EditCommand"
enableviewstate="true"
OnDeleteCommand="dl_DeleteCommand" onUpdateCommand="dl_UpdateCommand">
<HeaderTemplate>
<h1 style='text-align:center;color:#556B2F'>The Datalist At Work</h1>
</HeaderTemplate>
<itemtemplate>
<asp:linkbutton id="lb1" runat="server" Text='<%#container.dataitem("FirstName") & " " & container.dataitem("FirstName")%>' CommandName="Edit" enableviewstate="true" />
</itemtemplate>
<alternatingitemtemplate>
<asp:linkbutton id="lb2" runat="server" Text='<%#container.dataitem("FirstName") & " " & container.dataitem("FirstName")%>' CommandName="Edit" enableviewstate="true" />
</alternatingitemtemplate>
<selecteditemtemplate>
Name:<%#container.dataitem("FirstName") & " " & container.dataitem("FirstName")%><br>
City:<%#container.dataitem("City")%><br>
Region:<%#container.dataitem("Region")%>
</selecteditemtemplate>
<EditItemTemplate>
<asp:Linkbutton id="lb3" runat="server" CommandName="Cancel" Text="Cancel" />
<asp:Linkbutton id="lb4" runat="server" CommandName="Update" Text="Update" />
<asp:Linkbutton id="lb5" runat="server" CommandName="Delete" Text="Delete" />
</EditItemTemplate>
<footertemplate>
<h1 style='text-align:center;color:#556B2F'>Thank you for shopping</h1>
</footertemplate>
</asp:datalist>
</form>
</body>
</html>
Thanks in advance.
The following code does not fire-up EditItemTemplate. Could someone spot the error for me, please?
<%@ page language="vb" %>
<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient" %>
<script runat="server">
sub page_load( obj as object, e as eventargs)
dim con as sqlconnection=new sqlconnection("data source=(local);initial catalog=classNorthwind; integrated security=sspi;")
dim cmd as new sqlDataAdapter("select * from employees",con)
dim ds as dataset =new dataset
cmd.fill(ds,"customers")
dl.datasource=ds
dl.databind()
end sub
Sub dl_ItemCommand(obj as object, e as DataListCommandEventArgs)
dl.SelectedIndex=e.Item.ItemIndex
dl.databind
end sub
Sub dl_EditCommand(obj as object, e as DataListCommandEventArgs)
dl.SelectedIndex=e.Item.ItemIndex
dl.databind
end sub
Sub dl_CancelCommand(obj as object, e as DataListCommandEventArgs)
dl.SelectedIndex=-1
dl.databind
end sub
Sub dl_UpdateCommand(obj as object, e as DataListCommandEventArgs)
dl.databind
end sub
Sub dl_DeleteCommand(obj as object, e as DataListCommandEventArgs)
dl.databind
end sub
</script>
<html>
<head></head>
<body style="text-align:center;">
<Form runat="server">
<asp:datalist id="dl" runat="server" repeatlayout="table" repeatdirection="vertical" repeatcolumns ="1" datakeyfield="EmployeeID"
SelectedItemStyle-BackColor="#CCCC99" OnItemCommand="dl_ItemCommand" OnEditCommand="dl_EditCommand"
enableviewstate="true"
OnDeleteCommand="dl_DeleteCommand" onUpdateCommand="dl_UpdateCommand">
<HeaderTemplate>
<h1 style='text-align:center;color:#556B2F'>The Datalist At Work</h1>
</HeaderTemplate>
<itemtemplate>
<asp:linkbutton id="lb1" runat="server" Text='<%#container.dataitem("FirstName") & " " & container.dataitem("FirstName")%>' CommandName="Edit" enableviewstate="true" />
</itemtemplate>
<alternatingitemtemplate>
<asp:linkbutton id="lb2" runat="server" Text='<%#container.dataitem("FirstName") & " " & container.dataitem("FirstName")%>' CommandName="Edit" enableviewstate="true" />
</alternatingitemtemplate>
<selecteditemtemplate>
Name:<%#container.dataitem("FirstName") & " " & container.dataitem("FirstName")%><br>
City:<%#container.dataitem("City")%><br>
Region:<%#container.dataitem("Region")%>
</selecteditemtemplate>
<EditItemTemplate>
<asp:Linkbutton id="lb3" runat="server" CommandName="Cancel" Text="Cancel" />
<asp:Linkbutton id="lb4" runat="server" CommandName="Update" Text="Update" />
<asp:Linkbutton id="lb5" runat="server" CommandName="Delete" Text="Delete" />
</EditItemTemplate>
<footertemplate>
<h1 style='text-align:center;color:#556B2F'>Thank you for shopping</h1>
</footertemplate>
</asp:datalist>
</form>
</body>
</html>
Thanks in advance.
Last edited: