ItemCommandEvent of ADC Repeater Control
The suite of AJAX Data Controls have three major controls: Gridview, DataList, Repeater, in a progression of more flexibilities yet a bit less of in-built functionalities. In the code downloaded from www.dotnetslackers.com, there are many samples given for Gridview, though not nearly as many for the Repeater.
Makes sense, for Repeater gives you the wildest space to define your own data template, which means, you have to do your own plumbing.
For example, how does the commandEvent of ADC repeater work?
It took me a while to work out an dummy sample.
<%@ Page Language="C#" MasterPageFile="~/Site.master" Title="Repeater Render Bullet" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<h4>Categories</h4>
<AjaxData:Repeater ID="Repeater1" runat="server" ItemDataBoundEvent="onItemDataBound"
RenderAs="Ul" ItemCommandEvent="onItemCommad">
<ItemTemplate>
<li><input button="View"></span><span id="spnName"></span></li>
</ItemTemplate>
</AjaxData:Repeater>
<script type="text/javascript">
function pageLoad(sender, e)
{
DataService.GetAllCategory(onLoadSuccess);
}
function onLoadSuccess(result)
{
var repeater = Repeater1;
repeater.set_dataSource(result);
repeater.dataBind();
}
function onItemCommand(sender, e) {
var item = e.get_item();
if (item.get_isDataItemType()) {
if(e.commandName =="View")
alert('You clicked me');
}
}
function onItemDataBound(sender, e)
{
var item = e.get_item();
if (item.get_isDataItemType())
{
var category = item.get_dataItem();
var spnName = item.findControl('spnName');
setText(spnName, category.Name);
}
}
function setText(element, text)
{
if (typeof element.textContent != 'undefined')
{
element.textContent = text;
}
else if (typeof element.innerText != 'undefined')
{
element.innerText = text;
}
}
</script>
</asp:Content>