AllInWorld99 provides a reference manual covering many aspects of web programming, including technologies such as HTML, XHTML, CSS, XML, JavaScript, PHP, ASP, SQL,FLASH, jQuery, java, for loop, switch case, if, if else, for...of, for...in, for...each,while loop, blogger tips, blogger meta tag generator, blogger tricks, blogger pagination, client side script, html code editor, javascript editor with instant output, css editor, online html editor, materialize css tutorial, materialize css dropdown list,break, continue statement, label,array, json, get day and month dropdown list using c# code, CSS button,protect cd or pendrive from virus, cordova, android example, html and css to make android app, html code play,telerik show hide column, Transparent image convertor, copy to clipboard using javascript without using any swf file, simple animation using css, SQL etc. AllInWorld99 presents thousands of code examples (accompanied with source code) which can be copied/downloaded independantly. By using the online editor provided,readers can edit the examples and execute the code experimentally.


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:-
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>



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);
}


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();
}

Advertisement

0 comments:

Post a Comment

Notification

Total Pageviews