1
votes

I have a form with Search User Button when I select the button the modal popup extender will show and user can search all the employees, when select value, the value selected should pass to the parent form with another gridview.

Now, I have a code which convert dataview to datatable. When debugging the value of index (s) is not passing to (idx).

Dim RowIndex As Integer = gvUser.EditIndex
    Dim dt As New DataTable
    dt = TryCast(Session("dbCache_User"), DataView).Table.Clone

    Dim dv As New DataView(dt, "", "USR_IDNTY", DataViewRowState.OriginalRows)
    Dim s As String = TryCast(gvUser.Rows(RowIndex).FindControl("lblUSR_IDNTY"), Label).Text
    Dim idx As Integer = dv.Find(s)

    dv(idx)("USR_ID") = row.Cells(1).Text
    dv(idx)("NAME") = row.Cells(2).Text

    gvUser.DataSource = dv
    gvUser.DataBind()

When I'm trying to debug. I try to search one row with index 4; the value of (s) is 4 but when passing to (idx) it is -1.

I need to find the value s.

1

1 Answers

0
votes

It seems like you may not have read the relevant documentation. This is from the documentation for the DataTable.Clone method:

Clone creates a new DataTable with the same structure as the original DataTable, but does not copy any data (the new DataTable will not contain any DataRows). To copy both the structure and data into a new DataTable, use Copy.

If dv is a view of dt and dt contains no rows then of course Find returns -1. Even without reading that documentation, why did you not pickup that your DataTable was empty? That's one of the first things you should have checked.