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">
<aspataList 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>
</aspataList>
</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">
<aspataList 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>
</aspataList>
</form>
What I would like to know is are there any advantages/disadvantages of
the first approach over the second one or vice-versa?
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">
<aspataList 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>
</aspataList>
</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">
<aspataList 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>
</aspataList>
</form>
What I would like to know is are there any advantages/disadvantages of
the first approach over the second one or vice-versa?