Danish Habib

Danish Habib

  • NA
  • 694
  • 232.8k

Gridview Editing issue

Feb 10 2016 8:07 AM
I have four tables and i am getting data from these four table in gridview rowediting , I have used NExtResult  in my code when i execute the store procedure it shows two records but when the code vb.net execute after the next result it does not loop through the next row mean that it just showing the first row below is the code and i have 4 select statement that is why i am using next result () method , my Districts are 10 means ten rows when i execute stored procedure but when the code runs i.e. in edit mode i have to checked the checkboxlist item whose value are present in db it just check the first checkboxlist item mean the while loop ends after nextresult method 

Private Sub grdUsers_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles grdUsers.RowEditing

ViewState("Pflag") = True

count = count + 1

MakeTrue(Pflag)

Dim Tehsilid As String = Nothing

Dim DistrictId As String = Nothing

Dim UCId As String = Nothing

Dim villageID As String = Nothing

Dim cnnUser As New SqlConnection(AppSettings("DbSqlPortal"))

Dim cmdUser As New SqlCommand("FirstCREATE", cnnUser)

Dim drUser As SqlDataReader = Nothing

cmdUser.CommandType = CommandType.StoredProcedure

cmdUser.Parameters.Add("@UserId", SqlDbType.BigInt).Value = CInt(grdUsers.DataKeys(e.NewEditIndex).Value)

Dim litUserIds As Integer = CInt(grdUsers.DataKeys(e.NewEditIndex).Value).ToString()

cnnUser.Open()

drUser = cmdUser.ExecuteReader()

If drUser.HasRows Then

While (drUser.Read())

DisplayInitialForm()

litUserId.Text = CInt(drUser("UserId"))

txtFullName.Text = drUser("FullName")

txtEmail.Text = drUser("Email")

txtPassword.Text = drUser("Password")

txtAnswer.Text = drUser("SecurityAnswer")

ddlSecurityQuestions.SelectedValue = drUser("SecurityQuestion")

chkAdmin.Checked = drUser("IsAdmin")

ddlOrganization.SelectedValue = drUser("OrganizationId")

chkActive.Checked = drUser("IsActive")

If drUser("Gender") = "M" Then

rbMale.Checked = True

ElseIf drUser("Gender") = "W" Then

rbFemale.Checked = True

End If

ChkIsReportAble.Checked = CBool(drUser("IsReportable"))

ddlUserTypes.SelectedValue = drUser("UserTypes")

ddlOrganization.SelectedValue = drUser("OrganizationID")

If drUser("UserTypes") = "4" Then

fillReportablePeopleListForPartner()

Else

fillReportablePeopleList()

End If

If ChkIsReportAble.Checked Then

ddlReporintUser.SelectedValue = Convert.ToString(drUser("ReporintPerson"))

End If


Dim i As Int32

Dim j As Int32

For i = 0 To CheckBoxList1.Items.Count - 1

Dim strChkID As String = drUser("DistrictID")

If CheckBoxList1.Items(i).Value = strChkID Then

CheckBoxList1.Items.Item(i).Selected = True

Else

End If

Next

PopulateTehsil()

If (drUser.NextResult()) Then

While drUser.Read()

For j = 0 To CheckBoxList2.Items.Count - 1

Dim strChkIDs As String = drUser("TehsilId").ToString()

If CheckBoxList2.Items(j).Value = strChkIDs Then

CheckBoxList2.Items.Item(j).Selected = True

End If

Next

Tehsilid &= drUser("TehsilId").ToString() & ","

Session("savedTehsil") = Tehsilid

End While

If Tehsilid IsNot Nothing Then

Dim word As String() = Tehsilid.Split(",")

For Each li In word

For j = 0 To CheckBoxList2.Items.Count - 1

If li = CheckBoxList2.Items.Item(j).Value Then

CheckBoxList2.Items.Item(j).Selected = True

End If

Next

Next

End If

End If

PopulateUcs()

If drUser.NextResult() Then

While drUser.Read()

For j = 0 To CheckBoxList3.Items.Count - 1

Dim strChkIDss As String = drUser("UCID").ToString()

If CheckBoxList3.Items(j).Value = strChkIDss Then

CheckBoxList3.Items.Item(j).Selected = True

End If

Next

UCId &= drUser("UCID").ToString() & ","

Session("seceltedUcs") = UCId

End While

If UCId IsNot Nothing Then

Dim wordss As String() = UCId.Split(",")

For Each li In wordss

For j = 0 To CheckBoxList3.Items.Count - 1

If li = CheckBoxList3.Items.Item(j).Value Then

CheckBoxList3.Items.Item(j).Selected = True

End If

Next

Next

End If

End If

PopulateVillages()

If drUser.NextResult Then

While drUser.Read()

For j = 0 To CheckBoxList4.Items.Count - 1

Dim strChkIDsss As String = drUser("VillageId").ToString()

If CheckBoxList4.Items(j).Value = strChkIDsss Then

CheckBoxList4.Items.Item(j).Selected = True

End If

Next

villageID &= drUser("VillageId").ToString() & ","

Session("VillagesID") = villageID

End While

If villageID IsNot Nothing Then

Dim wordsss As String() = villageID.Split(",")

For Each li In wordsss

For j = 0 To CheckBoxList4.Items.Count - 1

If li = CheckBoxList4.Items.Item(j).Value Then

CheckBoxList4.Items.Item(j).Selected = True

End If

Next

Next

End If

End If

End While

End If

End Sub