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

Access Rows and Cells in a Grid

3 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 24 Sep 2009, 02:59 PM
I am trying to loop through a grid and replace some values in certain cells. I am basically taking values from a text box, matching it to values in the grid and replacing those values with the value in another text box.  I can do this without any issue using a standard GridView.  How do I do this with RadGrid. RadGrid seems to not have a Rows object.

Here is my code that works fine with a GridView:

using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        GenerateUniqueData(3);
    }
    private void GenerateUniqueData(int name)
    {
        string initialnamevalue = this.TextBox1.Text;


        for (int i = 1; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].Cells[name].Text == initialnamevalue)
                GridView1.Rows[i].Cells[name].Text = this.TextBox2.Text;
            else
                initialnamevalue = GridView1.Rows[i].Cells[name].Text;
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 Sep 2009, 04:07 PM
Hi Chris,

How to access rows and cells in a RadGrid control you can learn from the following help article:
Accessing cells and rows

I hope this information helps. Please do not hesitate to contact us if other question arise.

All the best,
Pavlina
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.
0
Chris
Top achievements
Rank 1
answered on 24 Sep 2009, 05:18 PM
Would you mind providing a simple example based on my code above?  It should only be a few line of code for you guys.  In my example, I am looping through the GridView, getting the value from the 3rd column and checking to see if the values in the cells in the 3rd column are the same as my textbox value.  With RadGrid, I believe I can check for UniqueName instead of defining the column number. Thanks for you help.

0
Princy
Top achievements
Rank 2
answered on 25 Sep 2009, 04:53 AM
Hello Chris,

You can try out the following code  to achieve the required, using RadGrid:
aspx:
 <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" UniqueName="Column">                       
 </telerik:GridBoundColumn>  

c#:
 private void GenerateUniqueData() 
    { 
        string initialnamevalue = this.TextBox1.Text; 
 
        foreach(GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if(item["TransactionsID"].Text == initialnamevalue) 
                 item["TransactionsID"].Text = this.TextBox2.Text; 
           
        } 
    } 

Hope this help you gets started..
Princy.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Chris
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or