Now, I want to get the names of all my groups(ie, values of cells in a column) on a button click as follows
(note: the button is on the same page as grid, not inside the grid)
On Button Click Event :
foreach (GridItem item in rgGroups.Items)
{
GridDataItem ditem = item as GridDataItem;
if (ditem["GroupType"].Text.Trim() == "Customer") //GroupType is a Template Column
{
string grpname = ditem["GroupName"].Text; //GroupName is BoundColumn
customers.Add(gname);
}
}
listGroups.DataSource = customers;
listGroups.DataBind();
But, the string grpname is always null. Not sure, if this the right way.
Thanks,
Sri
18 Answers, 1 is accepted
Try the following code to achieve your scenario.
C#:
protected void Button1_Click(object sender, EventArgs e){ foreach (GridDataItem item in RadGrid2.Items) { string value = item["GroupName"].Text; }}Thanks,
Shinu.
<Columns> <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label> </ItemTemplate> </telerik:GridTemplateColumn> </Columns>protected void LinkButton1_Click(object sender, EventArgs e) { foreach (GridDataItem item in RadGrid1.MasterTableView.Items) { // Bound column string strName = item["Name"].Text; // Template Column string StrNAME = (item.FindControl("Label1") as Label).Text; } }Thanks,
Jayesh Goyani
Sri!!
I need cell click event on radgrid. And on cellclikc i need to take a particular cell value to trrieve the data from the db to bind to the form. After that i need to make invisible radgrid and i need the user fill some details by the user. Please let me know some idea of urs..
Please try with below link and let me know if any concern.
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-detect-single-and-double-click-in-itemcommand-of-radgrid.aspx#2478300
Thanks,
Jayesh Goyani
i want to place textbox in each cell of dynamic radgrid. i did this by itemtemplate and i have other columns in Radgrid.
i want save all the radgrid data into sqlserver table.
i want retrieve the textbox and other sells of data.
Thanks Bharath
About add textbox in dynamic grid : I will provide demo on tomorrow.
About save the data in Sql Server : for this you have to use jquery Ajax call to save the Data. because we can not access control in back end side which was dynamically added in client side.
Thanks,
Jayesh Goyani
Please try with the below code snippet.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Forum.aspx.cs" Inherits="Forum" %><!DOCTYPE html><html><head runat="server"> <title></title> <script src="Script/jquery-1.10.2.min.js"></script> <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> var GridData; function OnbuttonClient() { jQuery.ajax({ type: 'POST', contentType: 'application/json; charset=utf-8', data: '', dataType: 'JSON', url: 'Forum.aspx/BindGrid', success: function (result) { GridData = result.d; if (GridData.length > 0) { var divGridContainer = document.getElementById('divGridContainer'); divGridContainer.style.display = ""; var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); tableView.set_dataSource(GridData); tableView.dataBind(); } else { var divGridContainer = document.getElementById('divGridContainer'); divGridContainer.style.display = "none"; } }, error: function () { alert('Error on binding the data'); } }); return false; } function RowDataBound(sender, args) { var _name = args.get_item().get_cell("Name"); if (_name != null) { $(_name).empty(); var input = document.createElement("input"); input.type = "text"; input.value = args.get_dataItem().Name; _name.appendChild(input); } } function OnbuttonSaveClient() { var test = new Object(); var Employee = new Array(); var grid = $find("<%= RadGrid1.ClientID %>"); if (grid) { var MasterTable = grid.get_masterTableView(); var Rows = MasterTable.get_dataItems(); for (var i = 0; i < Rows.length; i++) { var row = Rows[i]; var emp = new Object(); emp.id = row.getDataKeyValue("ID"); emp.name = $(row.get_cell('Name')).find('input').val(); Employee.push(emp); } } test.Employee = Employee; jQuery.ajax({ type: 'POST', contentType: 'application/json; charset=utf-8', data: JSON.stringify(test), dataType: 'JSON', url: 'Forum.aspx/SaveData', success: function (result) { alert('success'); }, error: function () { alert('Error on binding the data'); } }); return false; } </script> </telerik:RadCodeBlock></head><body> <form id="form1" runat="server"> <div> <telerik:RadScriptManager ID="RadScriptManager1" EnablePageMethods="true" runat="server"> </telerik:RadScriptManager> <asp:Button ID="Button1" Text="Bind Grid" runat="server" OnClientClick="return OnbuttonClient();" /> <asp:Button ID="Button2" Text="Save Grid" runat="server" OnClientClick="return OnbuttonSaveClient();" /> <div id="divGridContainer" style="display: none;"> <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"> <MasterTableView HierarchyLoadMode="Client" DataKeyNames="ID,ParentID" ClientDataKeyNames="ID,ParentID"> <Columns> <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="Name"> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> <ClientSettings> <ClientEvents OnRowDataBound="RowDataBound" /> </ClientSettings> </telerik:RadGrid> </div> </div> </form></body></html> using System;using System.Collections.Generic;using System.Data;using System.Globalization;using System.IO;using System.Linq;using System.Net;using System.Text;using System.Web;using System.Web.Script.Services;using System.Web.Services;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.Data.OleDb;using System.Threading;using System.Collections;using System.DirectoryServices;public partial class Forum : System.Web.UI.Page{ protected void Page_Init(object source, System.EventArgs e) { } public void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { dynamic data = new[] { new { ID = "1", Name ="Name11",ParentID = "0"} }; RadGrid1.MasterTableView.DataSource = data; RadGrid1.DataBind(); } } protected void Page_PreRender(object sender, EventArgs e) { } [WebMethod] public static void SaveData(List<Employee> Employee) { //perform your DB operation } [WebMethod] public static List<Employee> BindGrid() { List<Employee> list = new List<Employee>(); ; Employee obj = new Employee(); obj.ID = "1"; obj.Name = "Name1"; list.Add(obj); obj = new Employee(); obj.ID = "2"; obj.Name = "Name2"; list.Add(obj); return list; } [Serializable] public class Employee { public string ID { get; set; } public string Name { get; set; } }}Let me know if any concern.
Thanks,
Jayesh Goyani
Hi
Webmaster
I saw this url for Multiple column for Autocomplete following url . But here mention DatasourceID="Sqldatasource" but i need use this same sample for call asmx method how will do this any one guide me.
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multicolumncombo/defaultcs.aspx
Hi
Webmaster
I saw this url for Multiple column for Autocomplete following url . But here mention DatasourceID="Sqldatasource" but i need use this same sample for call asmx method how will do this any one guide me. http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multicolumncombo/defaultcs.aspx
Hello Jaya,
My sincere apologies for late reply but is your problem is resolved.
Thanks,
Jayesh Goyani
Hi
Jayesh
Can you fix this most urgent
http://www.telerik.com/forums/autocompletebox---telerik-control
Please open a separate ticket/thread for every unrelated query you have. This way the information in the thread will be more consistent. Thus, it will be easier for you to search for information in your past threads.
Also, if someone is facing similar issue they would be able to find the solution faster.
Regards,
Viktor Tachev
Telerik
Hi,
could you please send me the code in VB.net if you are familiar with VB coding? I am having the same issue of reading cells from Radgride.
Hi
Jayesh Goyani
I have some issue for Telerikgrid with Select all checkbox and filter option.
How to implement a telerik grid having filter control and select all option(Check Box)..... The purpose is to filter grid row items from a list and then to cancel the selection of the filtered result set.
Can you fixed this?
Hi
Shinu
I have some issue for Telerikgrid with Select all checkbox and filter option.
How to implement a telerik grid having filter control and select all option(Check Box)..... The purpose is to filter grid row items from a list and then to cancel the selection of the filtered result set.
Can you fixed this?
Hi Jayesh,
I am not able to find control GridTemplateColumn with the code you suggested . In my case I have added GridTemplateColumn with checkbox dynamically from code behind and trying to get value of checkbox checked at custom Button click which is outside of Grid.
Tried below code but didnt worked. Your help in appreciated.
// Template Column
string StrNAME = (item.FindControl("Label1") as Label).Text;
Thank you.
Swati
