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

How to find a string value in the radgrid by FindItemByKeyValue

1 Answer 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sunn
Top achievements
Rank 1
Sunn asked on 17 Nov 2013, 04:41 PM

Hi there i have a radgrid on which i have to find a value and if the item is found then generate message

below is my code:

Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
        If IsAlreadyExist() Then
            ram.Alert("")
        Else
            If IsAlreadyAdded() Then
                ram.Alert("")
            Else
                employees()
            End If
 
 
        End If
    End Sub
and here is the IsAlreadyAdded mehtod in which iam trying to find a specific value in grid if it exists it will return false but FindItemBykeyValue isnt working.
Private Function IsAlreadyAdded() As Boolean
        'If rgListnk.MasterTableView.Items.Count > 0 Then
        Dim itm As GridDataItem = rg.MasterTableView.FindItemByKeyValue("DEFAULT", "Y")
 
        If IsNothing(itm) Then
            Return False
        Else
            Return True
        End If
 
    End Function
Thanks...

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Nov 2013, 04:36 AM
Hi Sunn,

When you use FindItemByKeyValue, it cannot access items that are not part of current page as this items simply does not exist. RadGrid build items only for current page records from its data source. Please try using GetDataKeyValue, as follows, you can cancel paging at first and enable it after.

VB:
RadGrid1.AllowPaging = False
RadGrid1.Rebind()
 For Each data As GridDataItem In RadGrid1.MasterTableView.Items
    Dim value As [String] = data.GetDataKeyValue("DataFieldName").ToString()       
    If value = "Y" Then
      'Your Code
    End If
 Next
RadGrid1.AllowPaging = True
RadGrid1.Rebind()

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