| Private Sub grdPerson_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdPerson.NeedDataSource |
| grdPerson.DataSource = DataSourcePeople |
| End Sub |
| Private Sub grdPerson_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPerson.PreRender |
| For Each item As Telerik.Web.UI.GridItem In grdPerson.MasterTableView.ItemsHierarchy |
| If item.OwnerTableView.Name = "Detail" Then |
| If DataSource.Select("ResourceID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("ResourceID") & "' AND PersonID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("PersonID") & "'").Length > 0 Then |
| If DataSource.Select("ResourceID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("ResourceID") & "' AND PersonID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("PersonID") & "'")(0)("Selected") = True Then |
| item.Selected = True |
| Else |
| item.Selected = False |
| End If |
| End If |
| End If |
| Next |
| End Sub |
| Dim dataitem As Telerik.Web.UI.GridDataItem = CType(e.DetailTableView.ParentItem, Telerik.Web.UI.GridDataItem) |
| If DataSource.Select("PersonID = '" & dataitem.GetDataKeyValue("PersonID") & "'").Length = 0 Then |
| ExpandPerson(dataitem.GetDataKeyValue("PersonID")) |
| End If |
| e.DetailTableView.DataSource = DataSource.Select("PersonID = '" & dataitem.GetDataKeyValue("PersonID") & "'", "Course ASC") |
| Private Sub grdPerson_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdPerson.ItemCommand |
| If e.CommandName = "ExpandCollapse" Then |
| For Each item As Telerik.Web.UI.GridItem In grdPerson.MasterTableView.ItemsHierarchy |
| If item.Selected Then |
| If DataSource.Select("ResourceID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("ResourceID") & "' AND PersonID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("PersonID") & "'").Length > 0 Then |
| Dim dr As DataRow = DataSource.Select("ResourceID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("ResourceID") & "' AND PersonID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("PersonID") & "'")(0) |
| dr("Selected") = True |
| dr("Hours") = CType(item.FindControl("txtHours"), TextBox).Text |
| dr("Minutes") = CType(item.FindControl("txtMinutes"), TextBox).Text |
| dr("Score") = CType(item.FindControl("txtScore"), TextBox).Text |
| dr("CompletionDate") = CType(item.FindControl("txtCompletionDate"), TextBox).Text |
| dr("CompletionDeadline") = CType(item.FindControl("txtCompletionDeadline"), TextBox).Text |
| End If |
| Else |
| If DataSource.Select("ResourceID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("ResourceID") & "' AND PersonID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("PersonID") & "'").Length > 0 Then |
| DataSource.Select("ResourceID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("ResourceID") & "' AND PersonID = '" & item.OwnerTableView.DataKeyValues(item.ItemIndex).Item("PersonID") & "'")(0)("Selected") = False |
| End If |
| End If |
| Next |
| End If |
| End Sub |
| Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound | |
| If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then | |
| 'the grid is EditMode | |
| Dim Item As GridEditableItem = e.Item | |
| End If | |
| If TypeOf (e.Item) Is GridDataItem Then | |
| 'the grid is not in editMode (DisplayMode) | |
| Dim dataBoundItem As GridDataItem = e.Item | |
| 'throw the conversion error because i dont have any ID yet | |
| Dim ID As Integer = dataBoundItem("DbId").Text | |
| End If | |
| End Sub |
| <Telerik:RadScriptBlock ID="cb1" runat="server"> |
| <script type="text/javascript" language="javascript"> |
| var myValue = '' |
| function getSelectedRowValue() |
| { |
| if (myValue) |
| return myValue; |
| else |
| return ''; |
| } |
| <link rel="stylesheet" href="\r\n var myValue = \u0027\u0027\r\n function getSelectedRowValue()\r\n {\r\n if (myValue)\r\n return myValue;\r\n else\r\n return \u0027\u0027;\r\n } \r\n function RowSelected(sender"> |
| 1<html> |
| 2 <head> |
| 3 <title>Bad Request</title> |
| 4 <style> |
| 5 body {font-family:"Verdana";font-weight:normal;font-size: 8pt;color:black;} |
| 6 p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} |
| 7 b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} |
| 8 h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } |
| 9 h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } |
| 10 pre {font-family:"Lucida Console";font-size: 8pt} |
| 11 .marker {font-weight: bold; color: black;text-decoration: none;} |
| 12 .version {color: gray;} |
| 13 .error {margin-bottom: 10px;} |
| 14 .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } |
| 15 </style> |
| 16 </head> |
| 17 <body bgcolor="white"> |
| 18 |
| 19 <span><h1>Server Error in '/SafetyTortilla' Application.<hr width=100% size=1 color=silver></h1> |
| 20 |
| 21 <h2> <i>HTTP Error 400 - Bad Request.</i> </h2></span> |
| 22 |
| 23 <hr width=100% size=1 color=silver> |
| 24 |
| 25 <b>Version Information:</b> ASP.NET Development Server 8.0.0.0 |
| 26 |
| 27 </font> |
| 28 |
| 29 </body> |
| 30</html> |
| 31 |
| </link> |
Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.SelectedIndexChanged
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{ If (item.Selected) Then
{
string strTxt = item["ProductName"].Text;
}
}
End Sub
I am able to do this and loop through each row in the grid. It will loop through 10 times which is the number of rows in the grid:
For Each GridDataItem RadGrid1.MasterTableView.Items
'Do something here
Next
But when I try to define the "item" I get errors. I tried this:
For Each Item As GridDataItem In RadGrid1.MasterTableView.Items
'Do Something Here Next
And This:
Dim Item As GridDataItem (I get error here telling me GridDataItem is not defined)
For Each GridDataItem In RadGrid1.MasterTableView.Items
'Do Something Here
Next
What Am I missing here?