OnItemCommand DataList

R

rn5a

The OnItemCommand in a DataList is raised whenever a Button is clicked
in the DataList. Assume that a DataList displays 3 columns & the
<HeaderTemplate> contains 3 LinkButtons - one for each column (to sort
the DataList). One way of doing this is by raising the OnItemCommand
event of the DataList like this:

<script runat="server">
Sub SortData(obj As Object, ea As DataListCommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:DataList ID="dl1" OnItemCommand="SortData" runat="server">
<HeaderTemplate>
<table border="2">
<tr>
<th><asp:LinkBuuton ID="lnk1" CommandArgument="col1" Text="COL1"
runat="server"/></th>
<th><asp:LinkBuuton ID="lnk2" CommandArgument="col2" Text="COL2"
runat="server"/></th>
<th><asp:LinkBuuton ID="lnk3" CommandArgument="col3" Text="COL3"
runat="server"/></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
...........
...........
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</form>

The other way of doing this is by raising the OnCommand event of the
LinkButtons instead of raising the OnItemCommand event of the DataList
like this:

<script runat="server">
Sub SortData(obj As Object, ea As CommandEventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<asp:DataList ID="dl1" runat="server">
<HeaderTemplate>
<table border="2">
<tr>
<th><asp:LinkBuuton ID="lnk1" OnCommand="SortData"
CommandArgument="col1" Text="COL1" runat="server"/></th>
<th><asp:LinkBuuton ID="lnk2" OnCommand="SortData"
CommandArgument="col2" Text="COL2" runat="server"/></th>
<th><asp:LinkBuuton ID="lnk3" OnCommand="SortData"
CommandArgument="col3" Text="COL3" runat="server"/></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
...........
...........
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</form>

What I would like to know is are there any advantages/disadvantages of
the first approach over the second one or vice-versa?
 

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,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top