This is a migrated thread and some comments may be shown as answers.

RadGrid Column Button

8 Answers 3079 Views
Grid
This is a migrated thread and some comments may be shown as answers.
$uren
Top achievements
Rank 1
$uren asked on 06 Apr 2011, 11:53 AM
How can i write the function in RadGrid Column button... ?

Thanks & Regards
  Suren

8 Answers, 1 is accepted

Sort by
0
$uren
Top achievements
Rank 1
answered on 06 Apr 2011, 12:20 PM
How can i print a Line Item details in a radgrid using the print button in that grid row... ? can anyone help in this.... ?
0
Shinu
Top achievements
Rank 2
answered on 06 Apr 2011, 12:31 PM
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
      }
  }
0
$uren
Top achievements
Rank 1
answered on 06 Apr 2011, 12:41 PM
thanks a lot buddy............

but how can i print that particular row.... using that button........?
0
Princy
Top achievements
Rank 2
answered on 06 Apr 2011, 02:26 PM
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.
0
$uren
Top achievements
Rank 1
answered on 07 Apr 2011, 05:28 AM
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> ?
        }            
    }
     
0
$uren
Top achievements
Rank 1
answered on 07 Apr 2011, 09:39 AM
can anyone help with this....?
0
Gopal
Top achievements
Rank 1
answered on 08 Nov 2016, 07:02 AM

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

 

 

 

 

 

 

 

 

 

 

 

0
Viktor Tachev
Telerik team
answered on 10 Nov 2016, 01:04 PM
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.
Tags
Grid
Asked by
$uren
Top achievements
Rank 1
Answers by
$uren
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Gopal
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or