Please help when i update a record in the dropdown list.
the dropdown list disapear when i click on the next record in the datable paging list
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function askConfirm(msg) {
alert(msg)
}
</script>
<script src="../Scripts/jquery-1.8.3.min.js"></script>
<script src="../Datatables/datatables.js"></script>
<link href="../Datatables/datatables.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("[id*=StudentGrid]").DataTable({
bLengthChange: true,
lengthMenu: [[15, 20, -1], [15, 20, "All"]],
bFilter: true,
bSort: true,
bPaginate: true
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit Record" Width="156px" Height="34px" />
</td>
<td rowspan="2"> </td>
</tr>
<tr>
<td colspan="4">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="StudentGrid" runat="server" AutoGenerateColumns="False" ItemStyle-Width="Auto" CellSpacing="1" ClientIDMode="Static">
<Columns>
<asp:CommandField ShowHeader="True" ShowSelectButton="True" />
<asp:TemplateField HeaderText="Admno" SortExpression="account">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("admno") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Admno" runat="server" Text='<%# Bind("admno") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Student Name" SortExpression="Name" />
<asp:TemplateField HeaderText="Class">
<ItemTemplate>
<asp:DropDownList ID="ddlCLASS" runat="server" Height="22px" Width="74px">
</asp:DropDownList>
<asp:Label ID="lblCategory2" runat="server" Text='<%# Eval("Class") %>' Visible="False"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stream">
<ItemTemplate>
<asp:DropDownList ID="ddlStream" runat="server" AutoPostBack="True" Height="21px" OnSelectedIndexChanged="ddlStream_SelectedIndexChanged" Width="98px">
</asp:DropDownList>
<asp:Label ID="lblCategory3" runat="server" Text='<%# Eval("Stream") %>' Visible="False"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Type">
<ItemTemplate>
<asp:DropDownList ID="ddlSTDTYPE" runat="server" Height="21px" Width="87px">
</asp:DropDownList>
<asp:Label ID="lblCategory" runat="server" Text='<%# Eval("STDTYPE") %>' Visible="False"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sex">
<ItemTemplate>
<asp:DropDownList ID="ddlSex" runat="server">
</asp:DropDownList>
<asp:Label ID="lblCategory4" runat="server" Text='<%# Eval("Sex") %>' Visible="False"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rclass">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("rclass") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Rclass" runat="server" Text='<%# Bind("rclass") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Colour" SortExpression="House">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("House") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Coloursd" runat="server" Text='<%# Bind("House") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ACNOS" HeaderText="ACNOS" SortExpression="ACNOS" />
<asp:CommandField HeaderText="View Payment Details" SelectText="PayDetails" ShowSelectButton="True" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
<script type="text/javascript">
//On UpdatePanel Refresh
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
$('[id$=StudentGrid]').prepend($("<thead></thead>").append($('[id$=StudentGrid]').find("tr:first"))).DataTable({
"responsive": true,
"sPaginationType": "full_numbers"
});
}
});
};
</script>
Dim conString As String = ConfigurationManager.ConnectionStrings("UNIFORMConnectionString").ConnectionString
Dim cl As String
Dim Rclassr As String
Dim admno As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim cmd As New SqlCommand("SELECT NAME, HOUSE, CLASS, STREAM, SEX, ADMNO, ACCOUNT, STATUS, STDTYPE,ACNOS,Rclass FROM Student")
StudentGrid.DataSource = Me.ExecuteQuery(cmd, "SELECT")
StudentGrid.DataBind()
'Required for jQuery DataTables to work.
StudentGrid.UseAccessibleHeader = True
StudentGrid.HeaderRow.TableSection = TableRowSection.TableHeader
End If
End Sub
Private Sub StudentGrid_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles StudentGrid.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Try
Dim ddlCountries As DropDownList = CType(e.Row.FindControl("ddlSTDTYPE"), DropDownList)
Dim cmd As New SqlCommand("SELECT DISTINCT STDTYPE FROM Student")
ddlCountries.DataSource = Me.ExecuteQuery(cmd, "SELECT")
ddlCountries.DataTextField = "STDTYPE"
ddlCountries.DataValueField = "STDTYPE"
ddlCountries.DataBind()
'Add Default Item in the DropDownList
ddlCountries.Items.Insert(0, New ListItem("Please select"))
'Select the Country of Customer in DropDownList
Dim country As String = CType(e.Row.FindControl("lblCategory"), Label).Text
ddlCountries.Items.FindByValue(country).Selected = True
Catch ex As Exception
End Try
'Find the DropDownList in the Row
Try
Dim ddlCountries2 As DropDownList = CType(e.Row.FindControl("ddlCLASS"), DropDownList)
Dim cmd2 As New SqlCommand("SELECT DISTINCT CLASS FROM Classcontrol")
ddlCountries2.DataSource = Me.ExecuteQuery(cmd2, "SELECT")
ddlCountries2.DataTextField = "CLASS"
ddlCountries2.DataValueField = "CLASS"
ddlCountries2.DataBind()
'Add Default Item in the DropDownList
ddlCountries2.Items.Insert(0, New ListItem("Please select"))
Dim country2 As String = CType(e.Row.FindControl("lblCategory2"), Label).Text
ddlCountries2.Items.FindByValue(country2).Selected = True
cl = country2
Catch ex As Exception
End Try
'Select the Country of Customer in DropDownList
Try
Dim ddlCountries3 As DropDownList = CType(e.Row.FindControl("ddlStream"), DropDownList)
Dim cmd3 As New SqlCommand("SELECT DISTINCT STREAM FROM classcontrol where class='" & cl & "'")
ddlCountries3.DataSource = Me.ExecuteQuery(cmd3, "SELECT")
ddlCountries3.DataTextField = "STREAM"
ddlCountries3.DataValueField = "STREAM"
ddlCountries3.DataBind()
'Add Default Item in the DropDownList
ddlCountries3.Items.Insert(0, New ListItem("Please select"))
'Select the Country of Customer in DropDownList
Dim country3 As String = CType(e.Row.FindControl("lblCategory3"), Label).Text
ddlCountries3.Items.FindByValue(country3).Selected = True
Catch ex As Exception
End Try
Try
Dim ddlCountries4 As DropDownList = CType(e.Row.FindControl("ddlSex"), DropDownList)
Dim cmd3 As New SqlCommand("SELECT DISTINCT Sex FROM Student")
ddlCountries4.DataSource = Me.ExecuteQuery(cmd3, "SELECT")
ddlCountries4.DataTextField = "SEX"
ddlCountries4.DataValueField = "SEX"
ddlCountries4.DataBind()
'Add Default Item in the DropDownList
ddlCountries4.Items.Insert(0, New ListItem("Please select"))
'Select the Country of Customer in DropDownList
Dim country4 As String = CType(e.Row.FindControl("lblCategory4"), Label).Text
ddlCountries4.Items.FindByValue(country4).Selected = True
Catch ex As Exception
End Try
End If
End Sub
Private Function ExecuteQuery(ByVal cmd As SqlCommand, ByVal action As String) As DataTable
'Dim conString As String = conString
Using con As New SqlConnection(conString)
cmd.Connection = con
Select Case action
Case "SELECT"
Using sda As New SqlDataAdapter()
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
Case "UPDATE"
con.Open()
cmd.ExecuteReader()
con.Close()
Exit Select
End Select
Return Nothing
End Using
End Function
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
Response.Write("<script>alert('THIS STREAM IS ALREADY FULL');</script>")
' 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
Dim message As String = "alert('No Stream is Allowed to Cream Class.')"
ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
dropDownList.ClearSelection()
' Dim item As Object = dropDownList.Items.FindByValue(streamr)
' If item IsNot Nothing Then
'item.Selected = True
'End If
' Dim country As String = TryCast(Row.FindControl("lblCountry"), Label).Text
Dim country As String = "Please select"
If dropDownList.Items.FindByValue(country) IsNot Nothing Then
dropDownList.Items.FindByValue(country).Selected = True
End If
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
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()
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