Get Row values in RadGrid?

Hello Gurus,

   Here i have attached both GridView and RadGrid.

 Here getting the row values working in normal Gridview, but it is not working in RadGrid.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<!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>
<script type = "text/javascript">
function GetSelectedRow(lnk) {
var row = lnk.parentNode.parentNode;
var rowIndex = row.rowIndex – 1;
var customerId = row.cells[0].innerHTML;
var city = row.cells[1].getElementsByTagName("input")[0].value;
alert("RowIndex: " + rowIndex + " CustomerId: " + customerId + " City:" + city);
return false;
}
</script>
</head>
<body>

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

<asp:ScriptManager ID="Sc1" runat="server"></asp:ScriptManager>

<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns = "false" AllowPaging = "true" OnPageIndexChanging = "PageIndexChanging">
<Columns>
<asp:BoundField DataField = "CustomerID" HeaderText = "CustomerID" />
<asp:TemplateField HeaderText = "City">
<ItemTemplate>
<asp:TextBox ID="txtCity" runat="server" Text = ‘<%# Eval("City") %>’></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelect" runat="server" Text="Select" CommandName = "Select" OnClientClick = "return GetSelectedRow(this)" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="false" Width="97%">

<PagerStyle Mode="NumericPages"></PagerStyle>
<MasterTableView AutoGenerateColumns="False"
Width="100%" CommandItemDisplay="Top" PageSize="5">
<Columns>

<telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
<ItemTemplate>
<asp:TextBox ID="txtCity" runat="server" Text = ‘<%# Eval("City") %>’></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>

<telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
<ItemTemplate>
<asp:LinkButton ID="lnkSelect" runat="server" Text="Select" CommandName = "Select" OnClientClick = "return GetSelectedRow(this)" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>

</MasterTableView>

</telerik:RadGrid>

</form>
</body>
</html>

In telerik:

I tried this example,but it dont work.

http://www.telerik.com/help/aspnet-ajax/grid-getting-cell-values-for-selected-rows-client-side.html

Help with this.

Thanks in Advance.

Have you tried using the DataKey prpoperty of Grid ?

Leave a Reply