Please help how can i bookmark a record and return to it after update and binding in a gridview.
in this case i wanted to use the admno number.
admno = DirectCast(StudentGrid.Rows(index).Cells(1).FindControl("admno"), Label).Text
Protected Sub ddlStream_SelectedIndexChanged(sender As Object, e As EventArgs)
' Dim name As String = StudentGrid.SelectedRow.Cells(8).Text
'Dim rclassr As String = StudentGrid.SelectedRow.Cells(2).Text
Dim dropDownList As DropDownList = CType(sender, DropDownList)
Dim gvrow As GridViewRow = CType(sender, DropDownList).NamingContainer
Dim rowindex As Integer = CType(gvrow, GridViewRow).RowIndex
'Dim country As String = ddlcountry.SelectedValue
'Response.Redirect("Report.aspx?country=" & country)
Dim dif As Double
Dim index As Integer = rowindex
Dim ddl As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlCLASS"), DropDownList)
Dim ddltype As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlSTDTYPE"), DropDownList)
Rclassr = DirectCast(StudentGrid.Rows(index).Cells(7).FindControl("Rclass"), Label).Text
admno = DirectCast(StudentGrid.Rows(index).Cells(1).FindControl("admno"), Label).Text
Dim Coloursd As String = DirectCast(StudentGrid.Rows(index).Cells(8).FindControl("Coloursd"), Label).Text
' Dim Coloursd As String = StudentGrid.SelectedRow.Cells(8).Text
Dim text As String = ddl.SelectedItem.Text
Dim value As String = ddl.SelectedItem.Value
Dim valuestdype As String = ddltype.SelectedItem.Value
'Get the ID of the DropDownList.
Dim id As String = dropDownList.ID
Dim streamr As String = dropDownList.SelectedValue
Dim classr As String = value
Using Cont As New SqlConnection(conString)
Cont.Open()
Using cmd As New SqlCommand
cmd.Connection = Cont
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "Controlclasscream"
cmd.Parameters.Add("@c", SqlDbType.NVarChar).Value = classr
cmd.ExecuteReader()
Cont.Close()
End Using
End Using
Using Con As New SqlConnection(conString)
Con.Open()
Using Com As New SqlCommand("Select * from Newstreamtrap where stream = '" & streamr & "'", Con)
Using RDR = Com.ExecuteReader()
If RDR.HasRows Then
Do While RDR.Read
dif = RDR.Item("dif").ToString()
If dif <= 0 Then
Dim message As String = "alert('THIS STREAM IS ALREADY FULL.')"
ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
' Dim text As String = "SomeText"
dropDownList.ClearSelection()
Dim item As Object = dropDownList.Items.FindByText("Please select")
If item IsNot Nothing Then
item.Selected = True
End If
' dropDownList.Items.FindByValue("Please select").Selected = False
Exit Sub
End If
Loop
End If
End Using
End Using
Con.Close()
End Using
Using Con As New SqlConnection(conString)
Con.Open()
Using Com As New SqlCommand("Select * from Controlcream where stream = '" & streamr & "'", Con)
Using RDR = Com.ExecuteReader()
If RDR.HasRows Then
dropDownList.ClearSelection()
Dim country As String = "Please select"
If dropDownList.Items.FindByValue(country) IsNot Nothing Then
dropDownList.Items.FindByValue(country).Selected = True
End If
Dim message As String = "alert('No Stream is Allowed to Cream Class.')"
ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
BindGrid()
Exit Sub
Else
Using Conk As New SqlConnection(conString)
Conk.Open()
Using Comk As New SqlCommand("Distributecolor", Conk)
Using RDRk = Comk.ExecuteReader()
End Using
End Using
Conk.Close()
End Using
If valuestdype = "Old" Or valuestdype = "Old Repeater" Then
Using Cony As New SqlConnection(conString)
Cony.Open()
Using Comy As New SqlCommand("Select * from Colorsdata", Cony)
Using RDRy = Comy.ExecuteReader()
If RDRy.Read Then
Dim query As String = "UPDATE student SET House = @code,Stream = @code2 WHERE admno = @Id"
Dim constr As String = ConfigurationManager.ConnectionStrings("UNIFORMConnectionString").ConnectionString
Using contb As New SqlConnection(constr)
Dim command As New SqlCommand(query, contb)
command.Parameters.Add("@code", SqlDbType.NVarChar).Value = RDRy.Item("Color").ToString()
command.Parameters.Add("@code2", SqlDbType.NVarChar).Value = streamr
command.Parameters.Add("@Id", SqlDbType.NVarChar).Value = admno
DirectCast(StudentGrid.Rows(index).Cells(8).FindControl("Coloursd"), Label).Text = RDRy.Item("color").ToString()
contb.Open()
command.ExecuteNonQuery()
Cony.Close()
contb.Close()
End Using
End If
End Using
End Using
End Using
BindGrid()
Exit Sub
Else
If IsNothing(streamr) Then
dropDownList.ClearSelection()
Dim item As Object = dropDownList.Items.FindByText("Please select")
If item IsNot Nothing Then
item.Selected = True
End If
Else
Using Cony As New SqlConnection(conString)
Cony.Open()
Using Comy As New SqlCommand("Select * from Colorsdata", Cony)
Using RDRy = Comy.ExecuteReader()
If RDRy.Read Then
Dim query As String = "UPDATE student SET House = @code,Stream = @code2 WHERE admno = @Id"
Dim constr As String = ConfigurationManager.ConnectionStrings("UNIFORMConnectionString").ConnectionString
Using contb As New SqlConnection(constr)
Dim command As New SqlCommand(query, contb)
command.Parameters.Add("@code", SqlDbType.NChar).Value = RDRy.Item("color").ToString()
command.Parameters.Add("@code2", SqlDbType.NVarChar).Value = streamr
command.Parameters.Add("@Id", SqlDbType.Int).Value = admno
DirectCast(StudentGrid.Rows(index).Cells(8).FindControl("Coloursd"), Label).Text = RDRy.Item("color").ToString()
Cony.Open()
command.ExecuteNonQuery()
Cony.Close()
BindGrid()
End Using
End If
End Using
End Using
Exit Sub
' End If
' Loop
'End If
End Using
End If
End If
End If
End Using
End Using
End Using
Dim kd As String = IsNothing(Rclassr)
Using Con As New SqlConnection(conString)
Con.Open()
Using Com As New SqlCommand("Distributecolor", Con)
Using RDR = Com.ExecuteReader()
End Using
End Using
Con.Close()
End Using
If Rclassr <> streamr Then
Response.Write("<script>alert('No Stream is Allowed to Cream Class');</script>")
dropDownList.ClearSelection()
Dim item As Object = dropDownList.Items.FindByText(Rclassr)
If item IsNot Nothing Then
item.Selected = True
End If
End If
If Not IsNothing(Rclassr) AndAlso Not IsNothing(streamr) Then
Response.Write("<script>alert('No Stream is Allowed to Cream Class');</script>")
dropDownList.ClearSelection()
Dim item As Object = dropDownList.Items.FindByText(Rclassr)
If item IsNot Nothing Then
item.Selected = True
End If
End If
'Dim hold, khold, kclass As String
'sample
End Sub