RadGrid Column Button

9 posts, 0 answers
  1. $uren
    $uren avatar
    20 posts
    Member since:
    Apr 2011

    Posted 06 Apr 2011 Link to this post

    How can i write the function in RadGrid Column button... ?

    Thanks & Regards
      Suren
  2. $uren
    $uren avatar
    20 posts
    Member since:
    Apr 2011

    Posted 06 Apr 2011 Link to this post

    How can i print a Line Item details in a radgrid using the print button in that grid row... ? can anyone help in this.... ?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Apr 2011 Link to this post

    Hello,

    You can set the CommandName for the GridButtonColumn. Attach the event onItemCommand  to RadGrid and check for the e.commandName and write your code there. Here is a sample code.
    aspx:
    <telerik:RadGrid runat="server"  ID="RadGrid1" onitemcommand="RadGrid1_ItemCommand"">
               <MasterTableView DataKeyNames="EmpId" EditMode="InPlace">
                   <Columns>
                    <telerik:GridButtonColumn CommandName="Add" Text="Add" UniqueName="Add" HeaderText="Add">
                           </
    telerik:GridButtonColumn>
                    . . . . . . .

    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
      {
          if (e.CommandName == "Add")
          {
         // your code
          }
      }
  5. $uren
    $uren avatar
    20 posts
    Member since:
    Apr 2011

    Posted 06 Apr 2011 Link to this post

    thanks a lot buddy............

    but how can i print that particular row.... using that button........?
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Apr 2011 Link to this post

    Hello,


    I hope the following forum would help you to get started.
    How to print selected RadGrid row and add new link button in Command Item Template



    Regards,
    Princy.
  7. $uren
    $uren avatar
    20 posts
    Member since:
    Apr 2011

    Posted 07 Apr 2011 Link to this post

    ya i tried but my scenario is writing the function in grid button....

    can u help me in this ....

    java script
     <script type="text/javascript">
        function getOuterHTML(obj) {
            if (typeof (obj.outerHTML) == "undefined") {
                var divWrapper = document.createElement("div");
                var copyOb = obj.cloneNode(true);
                divWrapper.appendChild(copyOb);
                return divWrapper.innerHTML
            }
            else
                return obj.outerHTML;
        }

        function PrintRadGrid() {
            var previewWnd = window.open('about:blank', '', '', false);
            var sh = '<%= ClientScript.GetWebResourceUrl(dg_Shiplab.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",dg_Shiplab.Skin)) %>';
            var shBase = '<%= ClientScript.GetWebResourceUrl(dg_Shiplab.GetType(),"Telerik.Web.UI.Skins.Grid.css") %>';
            var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link>";
            styleStr += "<link href = '" + shBase + "' rel='stylesheet' type='text/css'></link></head>";
            var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= dg_Shiplab.ClientID %>').get_element()) + "</body></html>";
            previewWnd.document.open();
            previewWnd.document.write(htmlcontent);
            previewWnd.document.close();
            previewWnd.print();
            previewWnd.close();
        }
        </script>
    I want to call this script in this event...

    protected void dg_EditCommand1(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
               <script> ?
            }            
        }
         
  8. $uren
    $uren avatar
    20 posts
    Member since:
    Apr 2011

    Posted 07 Apr 2011 Link to this post

    can anyone help with this....?
  9. Gopal
    Gopal avatar
    1 posts
    Member since:
    Mar 2016

    Posted 08 Nov Link to this post

    Hi,

    I am using telerik image button in my grid but I am not able to handle click event.

    Actually the button is for star mark, when user click on that button then startmark will be filled(i.e. I will show another image and get that row information and store in database. 

    I Created one datatable dt and set datasourse= dt for rad grid

    then I create one GridButtonColumn, but when user click on that button It goes to server but not fire RadGrid1_ItemCommand event

    this is my radgrid data:

      <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" GroupPanelPosition="Top" PageSize="50" Skin="Metro" AllowPaging="True" BorderStyle="None" ForeColor="#666666" OnItemCommand="RadGrid1_ItemCommand">
                        <GroupingSettings CollapseAllTooltip="Collapse all groups" />
                        <SortingSettings EnableSkinSortStyles="False" />
                        <ExportSettings FileName="Export Auction">
                        </ExportSettings>
                        <ClientSettings AllowRowHide="True" EnablePostBackOnRowClick="True" EnableRowHoverStyle="True">
                            <Selecting EnableDragToSelectRows="False" />
                        </ClientSettings>
                        <MasterTableView EnableLinqGrouping="False" GroupsDefaultExpanded="False" HierarchyLoadMode="ServerBind">
                            <CommandItemSettings ShowExportToCsvButton="True" ShowExportToExcelButton="True" ShowExportToPdfButton="True" ShowExportToWordButton="True" />
                            <Columns>
                                <telerik:GridButtonColumn ButtonType="ImageButton" CommandArgument="watch" CommandName="watch" FilterControlAltText="Filter watch column" HeaderText="W" ImageUrl="images/star-blank.png" Text="Add to Watchlist" UniqueName="watch">
                                </telerik:GridButtonColumn>
                            </Columns>
                        </MasterTableView>
                        <FooterStyle BackColor="#666666" BorderStyle="None" ForeColor="White" />
                        <HeaderStyle BackColor="#666666" BorderStyle="None" ForeColor="White" />
                    </telerik:RadGrid>

     

     

    In Page load I create this table

     DataTable dt=new DataTable();

    dt.Columns.Add("Sr.", typeof(int));
                    dt.Columns.Add("Domain", typeof(string));
                    dt.Columns.Add("col1", typeof(string));
                    dt.Columns.Add("col2", typeof(string));
                    dt.Columns.Add("col3", typeof(string));

    RadGrid1.DataSource=dt;

     

    This is my itemCommand method

     

     protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
            {
                if (e.CommandName == "watch")
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    string domain = item["Domain"].ToString();
                    
                }
            }

     

     

     

     

     

     

     

     

     

     

     

  10. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 10 Nov Link to this post

    Hi Gopal,

    I tried to replicate the behavior you describe, however I was not able to. Please check out the attached sample I used for testing. The ItemCommand is fired as expected on my end.

    I would appreciate it if you let me know what should be modified in the sample in order to replicate the behavior you are seeing.


    Regards,
    Viktor Tachev
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017