Server side onclick event for GridButtonColumn

4 posts, 0 answers
  1. James O'Brien
    James O'Brien avatar
    19 posts
    Member since:
    Oct 2009

    Posted 12 Oct 2009 Link to this post

    All I want to do is click on the CourseName colunm (GridButtonColunm) below and launch an event then retrive the data from that rows bound fields. Please Help.


    <telerik:RadGrid   
                                        ID="RadGridResults"   
                                        runat="server" AllowSorting="True" 
                                        AutoGenerateColumns="False" GridLines="None"   
                                        AllowMultiRowSelection="True" Skin="Web20" Font-Bold="False"   
                                        Font-Italic="False" Font-Names="Verdana" Font-Overline="False"   
                                        Font-Strikeout="False" Font-Underline="False"   
                                        OnItemCommand="RadGridResults_ItemCommand">  
                                        <MasterTableView Font-Bold="False" Font-Italic="False" Font-Names="Verdana"   
                                             Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Font-Size="11px" OnItemCommand="RadGridProduct_ItemCommand">   
                                             <rowindicatorcolumn> 
                                                 <HeaderStyle Width="20px" /> 
                                             </rowindicatorcolumn> 
                                             <expandcollapsecolumn> 
                                                 <HeaderStyle Width="20px" /> 
                                             </expandcollapsecolumn> 
                                             <Columns> 
                                                <telerik:GridBoundColumn DataField="Sequence" Display="false"></telerik:GridBoundColumn> 
                                                 <telerik:GridClientSelectColumn UniqueName="colSelect" Display="True">  
                                                     <HeaderStyle Width="40px" Font-Bold="False" Font-Italic="False"   
                                                         Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                                                         HorizontalAlign="Center" Wrap="True" /> 
                                                     <ItemStyle BorderStyle="None" Font-Bold="False" Font-Italic="False"   
                                                         Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                                                         HorizontalAlign="Center" Wrap="True" /> 
                                                 </telerik:GridClientSelectColumn> 
                                                 <telerik:GridBoundColumn DataField="Location" HeaderText="Location"   
                                                     SortExpression="Location" UniqueName="colLocation">  
                                                     <HeaderStyle Width="110px" Font-Bold="True" Font-Italic="False"   
                                                         Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                                                         ForeColor="White" Wrap="True" /> 
                                                     <ItemStyle BorderStyle="None" /> 
                                                 </telerik:GridBoundColumn> 
                                                 <telerik:GridBoundColumn DataField="Products" HeaderText="PRODUCT"   
                                                     SortExpression="Product" UniqueName="colProduct">  
                                                     <HeaderStyle Width="100px" Font-Bold="True" Font-Italic="False"   
                                                         Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                                                         ForeColor="White" Wrap="True" /> 
                                                     <ItemStyle BorderStyle="None" /> 
                                                 </telerik:GridBoundColumn> 
                                                 <telerik:GridBoundColumn DataField="Sequence" Display="false"></telerik:GridBoundColumn> 
                                                 <telerik:GridButtonColumn   
                                                    DataTextField="CourseName"   
                                                    HeaderText="COURSE NAME"   
                                                    SortExpression="CourseName"   
                                                    Text="Button"   
                                                    UniqueName="colCourseName">  
                                                     <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False"   
                                                         Font-Strikeout="False" Font-Underline="False" ForeColor="White" Width="260px"   
                                                         Wrap="True" /> 
                                                     <ItemStyle BorderStyle="None" /> 
                                                 </telerik:GridButtonColumn> 
                                                 <telerik:GridBoundColumn DataField="StartDate" HeaderText="START DATE"   
                                                     SortExpression="StartDate" UniqueName="colStartDate"   
                                                     DataFormatString="{0:M/dd/yyyy}">  
                                                     <HeaderStyle Width="130px" Font-Bold="True" Font-Italic="False"   
                                                         Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                                                         ForeColor="White" Wrap="True" /> 
                                                     <ItemStyle BorderStyle="None" /> 
                                                 </telerik:GridBoundColumn> 
                                                 <telerik:GridBoundColumn DataField="TotalAvailSeats" HeaderText="SEATS"   
                                                     SortExpression="TotalAvailSeats" UniqueName="colTotalAvailSeats">  
                                                     <HeaderStyle Width="90px" Font-Bold="True"   
                                                         HorizontalAlign="Center" Font-Italic="False" Font-Overline="False"   
                                                         Font-Strikeout="False" Font-Underline="False" ForeColor="White" Wrap="True" /> 
                                                     <ItemStyle BorderStyle="None" HorizontalAlign="Center" /> 
                                                 </telerik:GridBoundColumn> 
                                             </Columns> 
                                             <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"   
                                                 Font-Strikeout="False" Font-Underline="False" Wrap="True" /> 
                                             <AlternatingItemStyle Font-Bold="False" Font-Italic="False"   
                                                 Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                                                 Wrap="True" /> 
                                         </MasterTableView> 
                                         <SelectedItemStyle Font-Bold="True" ForeColor="Maroon" Font-Italic="False"   
                                             Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                                             Wrap="True" BackColor="Silver" /> 
                                         <ClientSettings EnableRowHoverStyle="False" > 
                                             <Selecting AllowRowSelect="True" /> 
                                         </ClientSettings> 
                                     </telerik:RadGrid> 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Oct 2009 Link to this post

    Hello James,

    You can set the CommandName for the buttoncolumn and check for the commandName in the ItemCreated event of the grid to achieve the required. Check out the example below:
    aspx:
    <telerik:GridButtonColumn DataTextField="CourseName" HeaderText="COURSE NAME" 
    SortExpression="CourseName" Text="Button" UniqueName="colCourseName"  
    CommandName="CourseName"
         ....                 
    </telerik:GridButtonColumn> 

    c#:
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
        { 
            if (e.CommandName == "CourseName"
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                string strtxt = item["colProduct"].Text; 
     
            } 
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Levi
    Levi avatar
    1 posts
    Member since:
    Mar 2014

    Posted 08 Mar 2014 Link to this post

    I am using the trial right now, but I have the same question but with vb.Net.  When I convert the code, here is what I get:


    Protected Sub gdOrders_ItemCommand(source As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles gdOrders.ItemCommand
         If (e.CommandName = "GetOrder") Then
              Dim item As GridDataItem = CType(e.Item, GridDataItem)
              Dim strtxt As String = item("OrderID").Text
         End If
    End Sub

    It is returning a line space and I am simply trying to return the OrderID.  Any advice?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Mar 2014 in reply to Levi Link to this post

    Hi Levi,

    Please take a look at the following code snippet, it works fine at my end. Please make sure that you have not set the visibility of the OrderID column to false.

    ASPX:
    <telerik:GridButtonColumn HeaderText="ButtonColumn" Text="Button" UniqueName="ButtonColumn" CommandName="ButtonColumn">
    </telerik:GridButtonColumn>
    <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
    </telerik:GridBoundColumn>

    VB:
    Protected Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
       If e.CommandName = "ButtonColumn" Then
           Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
           Dim strtxt As String = item("OrderID").Text
           Response.Write(strtxt)
       End If
    End Sub

    Thanks,
    Princy
Back to Top