Telerik onrowdatabound and oncommand Function
Telerik onrowdatabound and oncommand Function
Telerik is the very easy tool for creating grid, that having two function for control when the grid row is bound and click, that is called OnCommand and OnRowDataBound. We should write this two methods are write into the <ClientSettings> tag.
Example:-
function commandfunction(sender,args)
{}
function rowboundfunction(sender,args)
{}
-----------
-----------
----------
<ClientSettings>
<ClientEvents OnCommand="commandfunction" OnRowDataBound="rowboundfunction" />
</ClientSettings>
-----------
-----------
The standard methods to use the function name for oncommand "gridname_OnCommand" and onrowdatabound function name is "gridname_OnRowDataBound"
Example:-
Explanation:-
onRowDataBound function is used for control the data when on row bound we can access data using "args.get_dataItem()["NameField"]" and we can check and doing some functionality, and the onCommand function is used for control if any event occur on the grid this function will be executed, eg: mainly used for pagination.
Example for onRowDataBound and OnCommand:-
PageMethods Success Function in Telerik
Advertisement
Telerik is the very easy tool for creating grid, that having two function for control when the grid row is bound and click, that is called OnCommand and OnRowDataBound. We should write this two methods are write into the <ClientSettings> tag.
Example:-
function commandfunction(sender,args)
{}
function rowboundfunction(sender,args)
{}
-----------
-----------
----------
<ClientSettings>
<ClientEvents OnCommand="commandfunction" OnRowDataBound="rowboundfunction" />
</ClientSettings>
-----------
-----------
The standard methods to use the function name for oncommand "gridname_OnCommand" and onrowdatabound function name is "gridname_OnRowDataBound"
Example:-
function RadID_OnRowDataBound(sender,args)
{}
function RadID_OnCommand(sender,args)
{}
-------------
-------------
-------------
<telerik:RadGrid ID="RadID" runat="server" Width="100%">
<MasterTableView EnableNoRecordsTemplate="true">
<NoRecordsTemplate>
<div>
There are no records to display
</div>
</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn HeaderText="Req Number" DataField="Req">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="School Name" DataField="School">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<ClientEvents OnCommand="RadID_OnCommand"
OnRowDataBound="RadID_OnRowDataBound" />
</ClientSettings>
</telerik:RadGrid>
{}
function RadID_OnCommand(sender,args)
{}
-------------
-------------
-------------
<telerik:RadGrid ID="RadID" runat="server" Width="100%">
<MasterTableView EnableNoRecordsTemplate="true">
<NoRecordsTemplate>
<div>
There are no records to display
</div>
</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn HeaderText="Req Number" DataField="Req">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="School Name" DataField="School">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<ClientEvents OnCommand="RadID_OnCommand"
OnRowDataBound="RadID_OnRowDataBound" />
</ClientSettings>
</telerik:RadGrid>
Explanation:-
onRowDataBound function is used for control the data when on row bound we can access data using "args.get_dataItem()["NameField"]" and we can check and doing some functionality, and the onCommand function is used for control if any event occur on the grid this function will be executed, eg: mainly used for pagination.
Example for onRowDataBound and OnCommand:-
function RadID_OnRowDataBound(sender,args)
{
var ViLnk = args.get_item().findElement("view");
var EdLnk = args.get_item().findElement("edit");
var PrLnk = args.get_item().findElement("process");
var Status= args.get_item().findElement("GrirdStatus");
Status.innerHTML = args.get_dataItem()["DBStatus"];
if (args.get_dataItem()["DBPermission"] == 1) {
EdLnk.style.display = '';
ViLnk.style.display = 'none';
PrLnk.style.display = '';
}
else
{
EdLnk.style.display = 'none';
ViLnk.style.display = '';
PrLnk.style.display = 'none';
}
if (args.get_dataItem()["DBEdit"] == 'enable')
{
lnkedit.style.display = '';
ViLnk.style.display = '';
PrLnk.style.display = 'none';
}
ViLnk.href = "javascript:fun_view(" + args.get_dataItem()["ID"] + ")";
lnkedit.href = "javascript:fun_edit(" + args.get_dataItem()["ID"] + ")";
PrLnk.href = "javascript:fun_process(" + args.get_dataItem()["ID"] +")";
}
function RadID_OnCommand(sender,args)
{
args.set_cancel(true);
var tableView = $find("<%= RadID.ClientID %>").get_masterTableView();
var pageSize = sender.get_masterTableView().get_pageSize();
var currentPageIndex = sender.get_masterTableView().get_currentPageIndex();
PageMethods.Calling_pagemethod(currentPageIndex * tableView.get_pageSize(), tableView.get_pageSize() + (currentPageIndex * tableView.get_pageSize()), Calling_pagemethod_success);
}
{
var ViLnk = args.get_item().findElement("view");
var EdLnk = args.get_item().findElement("edit");
var PrLnk = args.get_item().findElement("process");
var Status= args.get_item().findElement("GrirdStatus");
Status.innerHTML = args.get_dataItem()["DBStatus"];
if (args.get_dataItem()["DBPermission"] == 1) {
EdLnk.style.display = '';
ViLnk.style.display = 'none';
PrLnk.style.display = '';
}
else
{
EdLnk.style.display = 'none';
ViLnk.style.display = '';
PrLnk.style.display = 'none';
}
if (args.get_dataItem()["DBEdit"] == 'enable')
{
lnkedit.style.display = '';
ViLnk.style.display = '';
PrLnk.style.display = 'none';
}
ViLnk.href = "javascript:fun_view(" + args.get_dataItem()["ID"] + ")";
lnkedit.href = "javascript:fun_edit(" + args.get_dataItem()["ID"] + ")";
PrLnk.href = "javascript:fun_process(" + args.get_dataItem()["ID"] +")";
}
function RadID_OnCommand(sender,args)
{
args.set_cancel(true);
var tableView = $find("<%= RadID.ClientID %>").get_masterTableView();
var pageSize = sender.get_masterTableView().get_pageSize();
var currentPageIndex = sender.get_masterTableView().get_currentPageIndex();
PageMethods.Calling_pagemethod(currentPageIndex * tableView.get_pageSize(), tableView.get_pageSize() + (currentPageIndex * tableView.get_pageSize()), Calling_pagemethod_success);
}
PageMethods Success Function in Telerik
function Calling_pagemethod_success(result)
{
var tableView = $find("<%= RadID.ClientID %>").get_masterTableView();
tableView.set_dataSource(result);
tableView.set_virtualItemCount(result.length);
tableView.dataBind();
}
{
var tableView = $find("<%= RadID.ClientID %>").get_masterTableView();
tableView.set_dataSource(result);
tableView.set_virtualItemCount(result.length);
tableView.dataBind();
}
Advertisement
Post a Comment for "Telerik onrowdatabound and oncommand Function"