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

Geetting the Selected cell(multipule) values from Grid

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sumanth
Top achievements
Rank 2
sumanth asked on 03 Apr 2009, 08:35 AM
Hi
I am working on RADGRID.
My Requirement is like this
In My Grid in the all the coloumns contains(int) values from database
I alreaddy made a grid with cell Selection
My Problem is
I can any Cell in Grid(multipule)Selection ineed to get that Seleted Cell values.
I have to send the sum of all the selected values to the tooltip
Plz help to solve the issue
Thanks in Advanace
My code is like this
Gotit.Aspx

<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="gotit.aspx.cs" Inherits="dgtooltip.gotit" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml" >

 

<

 

head runat="server">

 

 

 

<title></title>

 

 

<style type="text/css">

 

 

.HoverClass

 

{

 

background-color: aqua;

 

 

}

 

.DefaultClass

 

{

 

background-color: white;

 

 

}

 

.ClickClass

 

{

 

background-color: blue;

 

}

</

 

style>

 

</

 

head>

 

<

 

script type="text/javascript">

 

 

function HandleCellClick(sender, args) {

 

 

var targetCell = args.get_domEvent().target;

 

sender.get_masterTableView().fireCommand(

"CellClick", args.get_itemIndexHierarchical() + "|" + targetCell.innerHTML);

 

}

 

 

function RowCreated(sender, eventArgs)

 

{

 

var dataItem = eventArgs.get_gridDataItem();

 

 

 

for (var i = 0; i < dataItem.get_element().cells.length; i++) {

 

dataItem._element.cells[i].onmouseover =

function() {

 

 

this.className = "HoverClass";

 

};

dataItem.get_element().cells[i].onmouseout =

function() {

 

 

var cssName = this.selected ? "HoverClass" : "DefaultClass"

 

 

this.className = cssName;

 

 

return;

 

};

dataItem.get_element().cells[i].onclick =

function() {

 

 

this.selected = this.selected == true ? false : true;

 

 

this.className = "ClickClass";

 

};

}

}

</

 

script>

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

 

<telerik:RadScriptManager runat="server">

 

 

</telerik:RadScriptManager>

 

 

 

<div>

 

<%

-- <asp:HiddenField ID="HiddenField1" runat="server" />--%>

 

 

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

 

 

ConnectionString="<%$ ConnectionStrings:ULTIMATE_NEWConnectionString2 %>"

 

 

SelectCommand="select id,id,id,ID from CustomerMaster"></asp:SqlDataSource>

 

 

<asp:Label ID="Label1" runat="server"

 

 

style="z-index: 1; left: 280px; top: 47px; position: absolute; height: 39px; width: 262px"

 

 

Text="Label"></asp:Label>

 

 

</div>

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

 

</telerik:RadAjaxManager>

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"

 

 

GridLines="Both"

 

 

style="z-index: 1; left: 10px; top: 88px; position: absolute; height: 105px; width: 531px">

 

 

<ClientSettings>

 

 

 

<ClientEvents OnRowCreated = "RowCreated" ></ClientEvents>

 

</

 

ClientSettings>

 

<

 

HeaderContextMenu>

 

<

 

CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

 

</

 

HeaderContextMenu>

 

<

 

MasterTableView AutoGenerateColumns="False" DataKeyNames="id,id1,id2,ID3"

 

 

DataSourceID="SqlDataSource1">

 

<

 

RowIndicatorColumn>

 

<

 

HeaderStyle Width="20px"></HeaderStyle>

 

</

 

RowIndicatorColumn>

 

<

 

ExpandCollapseColumn>

 

<

 

HeaderStyle Width="20px"></HeaderStyle>

 

</

 

ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="id" DataType="System.Int16" HeaderText="id"

 

 

ReadOnly="True" SortExpression="id" UniqueName="id">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="id1" DataType="System.Int16"

 

 

HeaderText="id1" ReadOnly="True" SortExpression="id1" UniqueName="id1">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="id2" DataType="System.Int16"

 

 

HeaderText="id2" ReadOnly="True" SortExpression="id2" UniqueName="id2">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="ID3" DataType="System.Int16"

 

 

HeaderText="ID3" ReadOnly="True" SortExpression="ID3" UniqueName="ID3">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

</

 

MasterTableView>

 

<

 

FilterMenu>

 

<

 

CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

 

</

 

FilterMenu>

 

 

</telerik:RadGrid>

 

 

</form>

 

</

 

body>

 

</

 

html>

Gotit.CS File

 

using

 

System;

 

 

 

using

 

System.Collections.Generic;

 

 

 

using

 

System.Linq;

 

 

 

using

 

System.Web;

 

 

 

using

 

System.Web.UI;

 

 

 

using

 

System.Web.UI.WebControls;

 

 

 

using

 

Telerik.Web.UI;

 

 

 

using

 

System.Windows.Forms;

 

 

 

using

 

System.Data;

 

 

 

using

 

System.Collections;

 

 

 

 

namespace

 

dgtooltip

 

{

 

 

public partial class gotit : System.Web.UI.Page

 

 

 

 

{

 

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

}

 

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)

 

{

 

 

if (e.Item is GridDataItem)

 

{

 

foreach (GridTableCell cell in e.Item.Cells)

 

{

cell.ToolTip = cell.Text;

}

}

}

 

 

protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)

 

{

Label1.Text = RadGrid1.SelectedItems.ToString();

}

 

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

if (e.CommandName == "CellClick")

 

{

 

string[] args = e.CommandArgument.ToString().Split('|');

 

RadGrid1.Items[

int.Parse(args[0])].Selected = true;

 

RadAjaxManager1.Alert(

"Cell contents: \n" + args[1]);

 

}

}

}

}

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 06 Apr 2009, 05:02 PM
Hello Sumanth,

To achieve your goal, you can use the approach from this online help article as a starting point. Then you just need to iterate through the rows and check whether the row's cells are selected in order to get their values.

Best regards,
Georgi Krustev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
sumanth
Top achievements
Rank 2
Answers by
Georgi Krustev
Telerik team
Share this question
or