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

[Solved] RadGrid Row Select Event

9 Answers 2964 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gopal
Top achievements
Rank 1
gopal asked on 01 Oct 2010, 09:59 AM
Hi,
   When a row is selected i want to rise an event to update a table with the values of selected row.
Can any one help on this issue.

Thanks,
Gopalakrishnan D

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Oct 2010, 10:18 AM
Hello Gopal,

The SelectedIndexChanged/ItemCommand event will be fired when you click the row if you have set EnablePostBackOnRowClick property to "True".


ASPX:
<ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
</ClientSettings>

C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
   {
       GridDataItem item =(GridDataItem )RadGrid1.SelectedItems[0];//get selected row
   }

Thanks,
Princy.
0
Jamie Webb
Top achievements
Rank 1
answered on 17 Jan 2011, 06:25 PM
I tried your code as I need to do the same thing but the SelectedItems didn't have any values in it?

SelectedItems.Count is 0 but I have selected and Item

0
Pavlina
Telerik team
answered on 18 Jan 2011, 01:05 PM
Hello Gopal,

I followed your scenario and prepared a sample project attached to this post. Could you please run it on your end and let me know if it works as expected and what differs in your case?

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
answered on 06 Dec 2011, 09:58 PM
I'm trying to implement this solution, and it's not producing an output.
0
Pavlina
Telerik team
answered on 09 Dec 2011, 01:06 PM
Hello Kevin,

Could you please elaborate a bit more on your scenario?  If you could share your grid declaration and any connected server code could help us provide a resolution for you. 

Kind regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
answered on 09 Dec 2011, 04:44 PM
I have a user control called directory.ascx...
<%@ Control Language="C#" Debug="true" AutoEventWireup="true" CodeFile="Copy of Directory.ascx.cs" Inherits="Directory" EnableViewState="True" ViewStateMode="Enabled" %>
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1">
    <div class="filterDiv">
        <telerik:RadFilter runat="server" ID="RadFilter1" FilterContainerID="RadGrid1" ShowApplyButton="false">
        </telerik:RadFilter>
    </div>
    <telerik:RadGrid runat="server" ID="RadGrid1" ShowGroupPanel="True" AutoGenerateColumns="false" PageSize="10" AllowPaging="true" AllowSorting="true" AllowFilteringByColumn="true" OnItemCommand="RadGrid1_ItemCommand" Skin="WebBlue" GroupingEnabled="true" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
        <PagerStyle Position="TopAndBottom" />
        <MasterTableView IsFilterItemExpanded="false" GroupLoadMode="Client" CommandItemDisplay="top">
            <CommandItemTemplate>
                <telerik:RadToolBar runat="server" ID="RadToolBar1" OnButtonClick="RadToolBar1_ButtonClick">
                    <Items>
                        <telerik:RadToolBarButton Text="Apply filter" CommandName="FilterRadGrid" ImageUrl="<%#GetFilterIcon() %>" ImagePosition="Right" />
                    </Items>
                </telerik:RadToolBar>
            </CommandItemTemplate>
            <Columns>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name" HeaderButtonType="TextButton" SortExpression="Name" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnName"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Jobtitle" HeaderText="Title" HeaderButtonType="TextButton" SortExpression="Jobtitle" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnJobtitle"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Email" HeaderText="Email" HeaderButtonType="TextButton" SortExpression="Email" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnEmail"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" HeaderButtonType="TextButton" SortExpression="Phone" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnPhone" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Categories" HeaderText="Categories" HeaderButtonType="TextButton" SortExpression="Categories" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnCategories"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Department" HeaderText="Department" HeaderButtonType="TextButton" SortExpression="Department" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnDepartment"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Building" HeaderText="Building" HeaderButtonType="TextButton" SortExpression="Building" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnBuilding" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Room" HeaderText="Room #" HeaderButtonType="TextButton" SortExpression="Room" HeaderStyle-HorizontalAlign="Center" ItemStyle-CssClass="directoryColumnRoom" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings AllowColumnsReorder="true" AllowDragToGroup="true" EnableRowHoverStyle="true" AllowGroupExpandCollapse="True" ReorderColumnsOnClient="True" ColumnsReorderMethod="Reorder" Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
            <Animation AllowColumnReorderAnimation="true" AllowColumnRevertAnimation="true" ColumnReorderAnimationDuration="2000" />
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
        <GroupingSettings ShowUnGroupButton="true" />
    </telerik:RadGrid>
</telerik:RadAjaxPanel>


Here's the code behind....
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.Events;
using Telerik.Sitefinity.Events.Model;
using Telerik.Web.UI;
using Telerik.Web;
 
public partial class Directory : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Hashtable buildings = new Hashtable(),
                         categories = new Hashtable(),
                         departments = new Hashtable();
 
        StockHashTable(ref buildings, "SELECT * FROM sf_list_items_building a INNER JOIN sf_taxa b ON a.val=b.id");
        StockHashTable(ref categories, "SELECT * FROM sf_list_items_categories a INNER JOIN sf_taxa b ON a.val=b.id");
        StockHashTable(ref departments, "SELECT * FROM sf_list_items_department a INNER JOIN sf_taxa b ON a.val=b.id");
 
        DataTable myDataTable = new DataTable();
        DataColumn[] cols = new DataColumn[8];
        cols[0] = new DataColumn("Name");
        cols[1] = new DataColumn("Jobtitle");
        cols[2] = new DataColumn("Email");
        cols[3] = new DataColumn("Phone");
        cols[4] = new DataColumn("Categories");
        cols[5] = new DataColumn("Department");
        cols[6] = new DataColumn("Building");
        cols[7] = new DataColumn("Room");
 
        myDataTable.Columns.Add(cols[0]);
        myDataTable.Columns.Add(cols[1]);
        myDataTable.Columns.Add(cols[2]);
        myDataTable.Columns.Add(cols[3]);
        myDataTable.Columns.Add(cols[4]);
        myDataTable.Columns.Add(cols[5]);
        myDataTable.Columns.Add(cols[6]);
        myDataTable.Columns.Add(cols[7]);
 
        string ConnString = @"Data Source=(local)\SQLEXPRESS;UID=choose;Password=guTrut56";
        SqlConnection conn = new SqlConnection(ConnString);
        conn.Open();
 
        SqlCommand cmd = new SqlCommand("SELECT * FROM sf_list_items a INNER JOIN sf_lists b ON a.parent_id=b.content_id WHERE b.url_name_='directory' AND a.visible='1'", conn);
        SqlDataReader rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            myDataTable.LoadDataRow(new object[] { rdr["last_name"] + ", " + rdr["first_name"], rdr["job_title"], rdr["email"], rdr["phone"], categories[rdr["content_id"].ToString()], departments[rdr["content_id"].ToString()], buildings[rdr["content_id"].ToString()], rdr["room"] }, true);
        }
        rdr.Close();
        conn.Close();
 
        RadGrid1.DataSource = myDataTable;
        //Bldg Query
        //Categories Query
        //Department
    }
 
    public void StockHashTable(ref Hashtable ht, string qryString)
    {
        string ConnString = @"Data Source=(local)\SQLEXPRESS;UID=choose;Password=guTrut56";
        SqlConnection conn = new SqlConnection(ConnString);
        conn.Open();
        SqlCommand cmd = new SqlCommand(qryString, conn);
        SqlDataReader rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            if (ht[rdr["content_id"].ToString()] != null)
                ht[rdr["content_id"].ToString()] += ", " + rdr["title_"].ToString();
            else
                ht[rdr["content_id"].ToString()] = rdr["title_"].ToString();
        }
        rdr.Close();
        conn.Close();
    }
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "FilterRadGrid")
        {
            RadFilter1.FireApplyCommand();
        }
    }
    protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
    {
        //
    }
    protected string GetFilterIcon()
    {
        return SkinRegistrar.GetWebResourceUrl(Page, typeof(RadGrid), string.Format("Telerik.Web.UI.Skins.{0}.Grid.Filter.gif", RadGrid1.Skin));
    }
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];
        string name = item["FirstName"].Text;
        if (name == null || name == "")
        {
            Response.Write("test -- null");
        }
        else
        {
            Response.Write("test -- full");
        }
    }
}

What I intend to do is place information from the selected item into a details section, but when I click on the item, the function "RadGrid1_SelectedIndexedChanged" doesn't seem to fire.
0
Pavlina
Telerik team
answered on 12 Dec 2011, 04:52 PM
Hello Kevin,

Please try populating the grid with data inside its NeedDataSource event handler instead of Page_Load and see if it makes any difference.

Regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Jorge
Top achievements
Rank 1
answered on 28 Jun 2014, 04:31 AM
Ja, ja, just have installed a demo version, and i thought that i cant understand the logical of the language, but i am seeing that anyone can do it. Your programm is very complicated. I am going to uninstall it and look for other program.
I have hear that devexpress is very easy to understand and fast to build web pages with asp.net. Not like yours.
Bye.
0
Pavlina
Telerik team
answered on 30 Jun 2014, 03:15 PM
Hello Jorge,

I checked out our records and noticed that you have not downloaded any trial licenses of the UI for ASP.NET AJAX controls. Are you sure that you are indeed testing with the real RadGrid?

Additionally, please specify what exactly you are not able to understand, so we can assist you further building your pages.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
gopal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jamie Webb
Top achievements
Rank 1
Pavlina
Telerik team
Jorge
Top achievements
Rank 1
Share this question
or