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

[Solved] Selecting cell values not getting right values

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
G S S
Top achievements
Rank 1
G S S asked on 24 Oct 2009, 12:16 AM
Hi,

When I bind a table to RADGrid, are the row headings the same as the table field names.

So when I bind all the rows in an entire table, and the table has rows a and b, are the row headings in RADGrid a and b.

I want to extract cell values from every row but only if the checkbox is selected (this is called "Checkbox1" in the Aspx):

My code is as follows:

        foreach (GridDataItem g in RadGrid1.MasterTableView.Items)
        {
            if ((g.FindControl("Checkbox1") as CheckBox).Checked)
            {
                var Title = ((sender as CheckBox).Parent.Parent as GridDataItem).Cells[0].Text;
                var Url = ((sender as CheckBox).Parent.Parent as GridItem).Cells[1].Text;

                // Add title and Url of feeds
                list.Add(new GenedRss(Url, Title));

            }
        }

Now I select the checkbox in the 4th row. My headings for the grid are like so:

Title Text Description XmlUrl HtmlUrl Type

But title variable is blank, and Url represents the title (so the 0 index of the cells collection). Shouldn't the title variable hold the title and the Url variable hold XmlUrl?

Can someone explain why this is not so?

Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Oct 2009, 08:21 AM
Hi,

A suggestion would be to access the columns using their  column UniqueNames( which would be the column names for the Autogenerated columns) rather than using the cell index. Generally the first two columns would include GridExpandCollapseColumn and the RowIndicatorColumn. So your data columns  cell index would start with  "2"

Refer the link below to know more on  Grid / Accessing Cells and Rows
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx

Thanks,
Princy
Tags
Grid
Asked by
G S S
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or