An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
error comes from this code below
Private Sub StudentGrid_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles StudentGrid.RowCommand
If e.CommandName = "Payment" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = StudentGrid.Rows(index)
Dim named As String = StudentGrid.Rows(index).Cells(1).Text
Dim namesd As String = StudentGrid.Rows(index).Cells(2).Text
Dim docment As String = StudentGrid.Rows(index).Cells(7).Text
admno = DirectCast(StudentGrid.Rows(index).Cells(1).FindControl("admno"), Label).Text
Dim names As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("Label1"), Label).Text
Dim rclass As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("Label3"), Label).Text
Dim rstream As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("Label4"), Label).Text
Dim rfather As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("lblCategory2"), Label).Text
Dim rmother As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("lblCategory3"), Label).Text
Dim raddress As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("Label2"), Label).Text
Dim rstatus As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("Label5"), Label).Text
'Dim ddl As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlClass"), DropDownList)
' Dim valueclass As String
'Dim ddlstr As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlStream"), DropDownList)
'Dim valuestream As String
' Response.Redirect(String.Format("~/Forms/Paymentdetail.aspx?admno={0}&Names={1}&class={2}&stream={3}", admno, names, valueclass, valuestream))
Session("account") = admno
Session("Names") = names
Session("Category") = "RECEPTION"
SName.Text = names
accounts.Text = admno
DropDownList1.SelectedItem.Text = rclass
Streamd.Text = rstream
Fcontact.Text = rfather
MotherContact.Text = rmother
Address.Text = raddress
Status.Text = rstatus
' Response.Redirect(String.Format("~/Forms/PatientBillPay.aspx"))
Else
If e.CommandName = "Staff" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = StudentGrid.Rows(index)
Dim named As String = StudentGrid.Rows(index).Cells(1).Text
Dim namesd As String = StudentGrid.Rows(index).Cells(2).Text
Dim docment As String = StudentGrid.Rows(index).Cells(7).Text
admno = DirectCast(StudentGrid.Rows(index).Cells(1).FindControl("admno"), Label).Text
Dim names As String = DirectCast(StudentGrid.Rows(index).Cells(2).FindControl("Label1"), Label).Text
Dim age As String = DirectCast(StudentGrid.Rows(index).Cells(3).FindControl("lblCategory2"), Label).Text
Dim Ptype As String = DirectCast(StudentGrid.Rows(index).Cells(4).FindControl("Label3"), Label).Text
Dim Phonet As String = DirectCast(StudentGrid.Rows(index).Cells(5).FindControl("lblCategory3"), Label).Text
' Dim ddl As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlClass"), DropDownList)
Dim valueclass As String = age
' Dim ddlstr As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlStream"), DropDownList)
Dim valuestream As String = Ptype
Response.Redirect(String.Format("~/Forms/staff.aspx?admno={0}&Names={1}&Age={2}&Ptype={3}&Phone={4}", admno, names, valueclass, valuestream, Phonet))
Else
If e.CommandName = "StreamPro" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = StudentGrid.Rows(index)
Dim ddl As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlCLASS"), DropDownList)
Dim ddl2 As Object = TryCast(StudentGrid.Rows(index).FindControl("ddlStream"), DropDownList)
' Rclassr = DirectCast(StudentGrid.Rows(index).Cells(1).FindControl("Rclass"), Label).Text
Dim text As String = ddl.SelectedItem.Text
Dim value As String = ddl.SelectedItem.Value
Dim text2 As String = ddl2.SelectedItem.Text
Dim value2 As String = ddl2.SelectedItem.Value
If String.IsNullOrEmpty(value) Or value = "Please select" Then
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('You Must Indicate Stream');", True)
Exit Sub
Else
Using Cont As New SqlConnection(conString)
Cont.Open()
Using cmd As New SqlCommand
cmd.Connection = Cont
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "Pushmissingstream"
cmd.Parameters.Add("@c", SqlDbType.NVarChar).Value = value
cmd.ExecuteReader()
Cont.Close()
End Using
End Using
Using Cont As New SqlConnection(conString)
Cont.Open()
Using cmd As New SqlCommand
cmd.Connection = Cont
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "Progressdataclass"
cmd.Parameters.Add("@c", SqlDbType.NVarChar).Value = value
cmd.ExecuteReader()
Cont.Close()
End Using
End Using
End If
Response.Redirect("~/Forms/StreamProgress.aspx")
' Response.Redirect("~/Forms/StreamProgress.aspx?class=" & "P1")
' ClientScript.RegisterStartupScript(Me.[GetType](), "Pop", "openModal2();", True)
End If
End If
End If
End Sub
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table class="dataTables_scrollHead">
<tr>
<td class="auto-style5">Student Name</td>
<td class="auto-style6">
<asp:TextBox ID="SName" runat="server" Width="117px"></asp:TextBox>
</td>
<td class="auto-style7">Class</td>
<td class="auto-style7">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>NONE</asp:ListItem>
<asp:ListItem>BABY</asp:ListItem>
<asp:ListItem>DAYCARE</asp:ListItem>
<asp:ListItem>NUR</asp:ListItem>
<asp:ListItem>TOP</asp:ListItem>
<asp:ListItem>P1</asp:ListItem>
<asp:ListItem>P2</asp:ListItem>
<asp:ListItem>P3</asp:ListItem>
<asp:ListItem>P4</asp:ListItem>
<asp:ListItem>P5</asp:ListItem>
<asp:ListItem>P6</asp:ListItem>
<asp:ListItem>P7</asp:ListItem>
</asp:DropDownList>
</td>
<td>Status</td>
<td class="auto-style14">
<asp:TextBox ID="Status" runat="server" Width="73px"></asp:TextBox>
</td>
<td class="auto-style14">Stream</td>
<td class="auto-style9">
<asp:TextBox ID="Streamd" runat="server" Width="31px"></asp:TextBox>
</td>
<td class="auto-style5">Father Contact</td>
<td class="auto-style10">
<asp:TextBox ID="Fcontact" runat="server" Width="95px"></asp:TextBox>
</td>
<td class="auto-style11">MotherConact</td>
<td class="auto-style13">
<asp:TextBox ID="MotherContact" runat="server" Width="83px"></asp:TextBox>
</td>
<td>Gurdian</td>
<td>
<asp:TextBox ID="Guard" runat="server" Width="97px"></asp:TextBox>
</td>
<td>Destination</td>
<td>
<asp:TextBox ID="Address" runat="server" Width="77px"></asp:TextBox>
</td>
<td>Driver</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="drived" DataTextField="DriverName" DataValueField="DriverName">
</asp:DropDownList>
<asp:SqlDataSource ID="drived" runat="server" ConnectionString="<%$ ConnectionStrings:STMISWEBConnectionString %>" SelectCommand="SELECT [DriverName] FROM [DriverNames]"></asp:SqlDataSource>
</td>
<td> </td>
<td>
</td>
<td>
<asp:Label ID="accounts" runat="server"></asp:Label>
</td>
<td>
<asp:Button ID="Button4" runat="server" Text="Update Details" />
</td>
</tr>
</table>
<table class="dataTables_scrollHead">
<tr>
<td colspan="2">
<asp:GridView ID="StudentGrid" runat="server" AutoGenerateColumns="False" CellSpacing="1" ClientIDMode="Static" EnableSortingAndPagingCallbacks="True" Height="190px" PageSize="30" ShowFooter="True" Width="1055px" EnableViewState="False">
<Columns>
<asp:TemplateField HeaderText="AcNo." SortExpression="account">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("account") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click1" Text="AddNew" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Admno" runat="server" Text='<%# Bind("account") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Height="16px" Text='<%# Bind("Name") %>' Width="181px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="Namesf" runat="server" Width="263px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Class">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Class") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlClass" runat="server">
<asp:ListItem>NONE</asp:ListItem>
<asp:ListItem>BABY</asp:ListItem>
<asp:ListItem>TOP</asp:ListItem>
<asp:ListItem>DAYCARE</asp:ListItem>
<asp:ListItem>P1</asp:ListItem>
<asp:ListItem>P2</asp:ListItem>
<asp:ListItem>P3</asp:ListItem>
<asp:ListItem>P4</asp:ListItem>
<asp:ListItem>P5</asp:ListItem>
<asp:ListItem>P6</asp:ListItem>
<asp:ListItem>P7</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Class") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stream">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Stream") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="Streamf" runat="server" Width="53px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Stream") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Father Contact">
<FooterTemplate>
<asp:TextBox ID="FAge" runat="server" Width="132px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblCategory2" runat="server" Text='<%# Bind("Phone2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mother Contact">
<FooterTemplate>
<asp:TextBox ID="FPhone" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblCategory3" runat="server" Text='<%# Eval("Phone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Guardian">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Height="18px" Text='<%# Bind("Guardian") %>' Width="88px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="Gurdiandata" runat="server" Text='<%# Bind("Guardian") %>' Width="83px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Guardian") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Destination" SortExpression="address">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" onkeyup="Capital(this)" Text='<%# Bind("address") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="FAddress" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Driver Name">
<FooterTemplate>
<asp:DropDownList ID="ddlSexF" runat="server" DataTextField="DriverName" DataValueField="DriverName" DataSourceID="driverdat">
<asp:ListItem>NONE</asp:ListItem>
<asp:ListItem>MALE</asp:ListItem>
<asp:ListItem>FEMALE</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="driverdat" runat="server" ConnectionString="<%$ ConnectionStrings:STMISWEBConnectionString %>" SelectCommand="SELECT [DriverName] FROM [DriverNames]"></asp:SqlDataSource>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblCategory4" runat="server" Text='<%# Eval("DriverName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Dates" HeaderText="DateTime" DataFormatString="{0:dd/MM/yyyy}" />
<asp:ButtonField CommandName="Payment" HeaderText="Edit" Text="Edit" />
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>