
Musab Alghzawi
Top achievements
Rank 1
Musab Alghzawi
asked on 31 Mar 2010, 10:42 AM
Hi,
How can I keep track of the first column in the selected row.
I remember in ASP.NET grid I use selectedRow.cells[1]
I want to pass the value of the first cell in the selected row. I have tried grid.selectedItems, grid.selectedvalue..etc non works
How can I do that in telerik grid ?
Thanks,
Musab
How can I keep track of the first column in the selected row.
I remember in ASP.NET grid I use selectedRow.cells[1]
I want to pass the value of the first cell in the selected row. I have tried grid.selectedItems, grid.selectedvalue..etc non works
How can I do that in telerik grid ?
Thanks,
Musab
16 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 31 Mar 2010, 11:45 AM
Hello Musab,
You could access a cell value in the RadGrid control using the column UniqueName property.
RadGrid1.SelectedItems[0] as GridDataItem)["ColumnUniqueName"].Text
For more information about this topic, examine the following articles:
Retrieving primary key field values for selected items
-Shinu.
0

Musab Alghzawi
Top achievements
Rank 1
answered on 01 Apr 2010, 07:50 AM
Hi chinu,
already tried this, I don't know what I'm missing because I cannot define new DataGriditem. Here is my code
already tried this, I don't know what I'm missing because I cannot define new DataGriditem. Here is my code
Protected Sub grdMain_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grdMain.SelectedIndexChanged |
'Reade selected ID from the grid |
con.Open() |
sql = "SELECT * FROM Sample WHERE Sample.ID = " + grdMain.SelectedItems("ID").ToString |
cmd = New SqlCommand(sql, con) |
rd = cmd.ExecuteReader() |
rd.Close() |
con.Close() |
End Sub |
0
Hello Musab,
I'm not sure that I understand what you want to accomplish. Could you please provide some more information / code-snippets?
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I'm not sure that I understand what you want to accomplish. Could you please provide some more information / code-snippets?
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Musab Alghzawi
Top achievements
Rank 1
answered on 04 Apr 2010, 07:10 AM
Hi Daniel,
Basically I'm binding data in the Gridview, say information about a book. In the grid I show books ID, Title, Author.
When I select a specific row, I wanna be able to show more details in text boxes based on the selected ID from the selected row.
So if you notice my code above, I have a select statement that I'm trying to make it depend on selected ID from the row. So I cannot continue the code unless I'm able to read the selected ID so i can use it in my SQL statement.
Regards,
Msaub
Basically I'm binding data in the Gridview, say information about a book. In the grid I show books ID, Title, Author.
When I select a specific row, I wanna be able to show more details in text boxes based on the selected ID from the selected row.
So if you notice my code above, I have a select statement that I'm trying to make it depend on selected ID from the row. So I cannot continue the code unless I'm able to read the selected ID so i can use it in my SQL statement.
Regards,
Msaub
0

Musab Alghzawi
Top achievements
Rank 1
answered on 07 Apr 2010, 10:49 AM
Any ideas ?
I just need the alternative of using selectedRow.cells[1] in asp.net grid
I just need the alternative of using selectedRow.cells[1] in asp.net grid
0
Hello Musab,
You can use the following code-snippet:
Alternatively you can access the cell by column's unique name, for example:
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
You can use the following code-snippet:
TableCell cell = RadGrid1.SelectedItems[0].Cells[1];
Alternatively you can access the cell by column's unique name, for example:
GridDataItem item = RadGrid1.SelectedItems[0]
as
GridDataItem;
TableCell cell = item[
"myColumnUniqueName"
];
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Musab Alghzawi
Top achievements
Rank 1
answered on 08 Apr 2010, 11:06 AM
I'm getting this error when I try both ways
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Stack
" at System.Collections.ArrayList.get_Item(Int32 index)
at Telerik.Web.UI.GridItemCollection.get_Item(Int32 index)
at WITLibrary.Main.grdMain_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\Mike\Documents\Visual Studio 2005\Projects\WITLibrary\WITLibrary\Main.aspx.vb:line 44
at Telerik.Web.UI.GridBaseDataList.OnSelectedIndexChanged(EventArgs e)
at Telerik.Web.UI.RadGrid.CallOnSelectedIndexChanged(EventArgs e)
at Telerik.Web.UI.RadGrid.RaisePostDataChangedEvent()
at Telerik.Web.UI.RadCompositeDataBoundControl.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
at System.Web.UI.Page.RaiseChangedEvents()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)"
0
Hello Musab,
Please test the attached sample project and let me know whether it this helps.
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Please test the attached sample project and let me know whether it this helps.
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Musab Alghzawi
Top achievements
Rank 1
answered on 11 Apr 2010, 08:07 AM
Hi Daniel,
Your code works, but when I apply it in my project I get the same error. I did a trace and quick watch and found out that this results
grdMain.Items(0).Cells(0).Text = " "
And when I count the number of cells in a specific row or selected item it counts the spaces, so let's say I have a title
Discovering Engineering
it counts 2 columns not one !!!
Any idea, I have to fix this cause I will use it again again in all the project. I'm using vb.net BTW, I'm not sure if this will make a difference
Your code works, but when I apply it in my project I get the same error. I did a trace and quick watch and found out that this results
grdMain.Items(0).Cells(0).Text = " "
And when I count the number of cells in a specific row or selected item it counts the spaces, so let's say I have a title
Discovering Engineering
it counts 2 columns not one !!!
Any idea, I have to fix this cause I will use it again again in all the project. I'm using vb.net BTW, I'm not sure if this will make a difference
0

Musab Alghzawi
Top achievements
Rank 1
answered on 11 Apr 2010, 08:51 AM
Currently I also get this output on selectedIndexChanged : RadGrid1.SelectedItems.cout = 0 !!
So it's not getting recognized that I'm selecting a row !!
Any idea ? non of our developers were able to solve this...could it be a bug ? it works in c# but not in vb.net
So it's not getting recognized that I'm selecting a row !!
Any idea ? non of our developers were able to solve this...could it be a bug ? it works in c# but not in vb.net
0

Mike Arasteh
Top achievements
Rank 1
answered on 12 Apr 2010, 08:22 AM
I'm Having the same problem
0

Musab Alghzawi
Top achievements
Rank 1
answered on 13 Apr 2010, 07:36 AM
It Could be a bug cause non of us were able to solve this
0

Musab Alghzawi
Top achievements
Rank 1
answered on 13 Apr 2010, 02:45 PM
Any idea ? Should I use asp.net gridview cause I can't wait any longer to get this issue fixed ?
0
Hello Musab,
And when I count the number of cells in a specific row or selected item it counts the spaces, so let's say I have a title...
The first columns in RadGrid are hidden, so if you try to access Cells[0] you will get the first cell which is probably empty. Please examine the attached demo that shows all columns in RadGrid together with their indexes.
Column types help topic
Currently I also get this output on selectedIndexChanged : RadGrid1.SelectedItems.cout = 0 !!
So it's not getting recognized that I'm selecting a row !!
Could you please post some code so I can examine your approach?
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
And when I count the number of cells in a specific row or selected item it counts the spaces, so let's say I have a title...
The first columns in RadGrid are hidden, so if you try to access Cells[0] you will get the first cell which is probably empty. Please examine the attached demo that shows all columns in RadGrid together with their indexes.
Column types help topic
Currently I also get this output on selectedIndexChanged : RadGrid1.SelectedItems.cout = 0 !!
So it's not getting recognized that I'm selecting a row !!
Could you please post some code so I can examine your approach?
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Musab Alghzawi
Top achievements
Rank 1
answered on 17 Apr 2010, 11:04 AM
Hi Daniel,
Here my code
It stops on the line of reading item as GridDataItem ... So I'm not able to ready the selected ID.
When I do QuickWatch on grdMain.Selectedrows.count I get ZERO
Here my code
Protected Sub grdMain_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grdMain.SelectedIndexChanged |
'Reade selected ID from the grid |
con.Open() |
Dim item As GridDataItem = TryCast(grdMain.SelectedItems(0), GridDataItem) |
Dim tmp As String = String.Format(item("ID").Text) |
sql = "SELECT * FROM Sample WHERE Sample.ID = " + tmp |
cmd = New SqlCommand(sql, con) |
rd = cmd.ExecuteReader() |
rd.Close() |
con.Close() |
End Sub |
It stops on the line of reading item as GridDataItem ... So I'm not able to ready the selected ID.
When I do QuickWatch on grdMain.Selectedrows.count I get ZERO
0
Hello Musab,
Your code runs flawlessly on my side - SelectedItems.Count is 1. Please open a new support ticket and attach a runnable version of your project to this ticket so we can debug it locally.
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Your code runs flawlessly on my side - SelectedItems.Count is 1. Please open a new support ticket and attach a runnable version of your project to this ticket so we can debug it locally.
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.