More in this section
Forums / Deployment / Gridview RowCommand

Gridview RowCommand

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Asit
    Asit avatar
    87 posts
    07 Nov 2009
    15 Dec 2009
    Link to this post
    Hi i m using a gridview in a user control and i m using this user control in a new page that i created in sitefinity.

    but the RowCommand event of gridview is not firing.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    15 Dec 2009
    Link to this post
    Hello asit pani,

    Thank you for using our services.

    The GridView RowCommand does fire. Would you like to show us how you bind to this command execution. Bellow is sample code of a user control with GridView bound to an IList containing content items. Please take a look at the code to see how I bind to the row command and based on command name do something with the command argument bubbled in this event:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="GridView.ascx.cs" Inherits="UserControls_GridView" %>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="true" PageSize="20" AutoGenerateColumns="false">
             <asp:TemplateField HeaderText="Name">
                    <asp:LinkButton ID="NameLink" runat="server"></asp:LinkButton>
             <asp:TemplateField HeaderText="Author">
                    <asp:Literal ID="Author" runat="server"></asp:Literal>

    and code file:
    using System;
    using System.Collections;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
    public partial class UserControls_GridView : System.Web.UI.UserControl
        protected void Page_Load(object sender, EventArgs e)
            //get news
            ContentManager cntManager = new ContentManager("News");
            IList NewsList = cntManager.GetContent();
            GridView1.DataSource = NewsList;
            //subscribe to events for Grid View
            GridView1.RowDataBound += new GridViewRowEventHandler(GridView_RowDataBound);
            //subscibre to the GridView Rowcommand event
            GridView1.RowCommand += new GridViewCommandEventHandler(GridView_RowCommand);
        //event handler for the RowCommand event
        void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
            if (e.CommandName == "Redirect")
        void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)
                IContent content = (IContent)e.Row.DataItem;
                LinkButton nameLink = (LinkButton)e.Row.FindControl("NameLink");
                Literal author = (Literal)e.Row.FindControl("Author");
                    nameLink.Text = content.GetMetaData("Title").ToString();
                if (content.GetMetaData("Author").ToString() != null)
                    author.Text = content.GetMetaData("Author").ToString();
                //pass command name and argument that will be bubbled in the Rowcommand event
                nameLink.CommandName = "Redirect";
                nameLink.CommandArgument = "";

    This should do the trick. It will redirect to the specified URL once the RowCommand fires.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered