Hello, I need help. I have a page for adding data in GridView1. After adding data from the textbox, it appears in GridView1 in the last row or column. I want it to appear in the first row.
What I have tried:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration
Imports System.Web.Security
Imports System.Collections
Imports System.IO
Public Class AddStudent
Inherits System.Web.UI.Page
Protected WithEvents HyperLink2 As System.Web.UI.WebControls.HyperLink
Protected WithEvents lblOutput As System.Web.UI.WebControls.Label
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList4 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label10 As System.Web.UI.WebControls.Label
Protected WithEvents Textbox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected connStr = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As System.Web.UI.WebControls.ValidationSummary
Protected WithEvents GridView1 As System.Web.UI.WebControls.GridView
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Textbox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents Label7 As System.Web.UI.WebControls.Label
Protected WithEvents Textbox3 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents Textbox4 As System.Web.UI.WebControls.TextBox
Protected WithEvents Textbox5 As System.Web.UI.WebControls.TextBox
Protected WithEvents Textbox6 As System.Web.UI.WebControls.TextBox
Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
Protected WithEvents Imagebutton1 As System.Web.UI.WebControls.ImageButton
Protected Connection = New SqlConnection(connStr)
Dim PageNo
#Region " Web Form Designer Generated Code "
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
PageNo = "5"
Dim Uname, usertype As String
Dim Connection As New SqlConnection(connStr)
Uname = Session.Contents("name")
Dim ds As New DataSet()
Dim adapter As New SqlDataAdapter("Select CONVERT(varchar(20),GETDATE(), 113) as STARTTIME, CONVERT(varchar(20),GETDATE(), 113) as CLOSETIME ,menuType from [HRusers] Where remarks like '%" & PageNo & "%' and userid = '" & Uname & "'", Connection)
adapter.Fill(ds, "Details")
If ds.Tables("Details").Rows.Count <> 0 Then
usertype = ds.Tables("Details").Rows(0).Item("MenuType").ToString()
Else
Response.Redirect("mainpage.aspx")
End If
End If
BindStudent()
End Sub
Dim ULOCATION, UCOUNTER, ptype
Dim utype As Char
Dim Bno
Sub BindStudent()
Dim Connection As New SqlConnection(connStr)
Dim adapter As New SqlDataAdapter("SELECT AID AS ACADEMICID, SNAME as STUDENTNAME,building as Department, Email as STATUS,LOCATION,MEALTYPE, CONVERT(varchar(20), STARTTIME, 113) as STARTTIME, CONVERT(varchar(20),endTIME, 113) as CLOSETIME,CREATEDBY FROM STUDENT where mobile is null or MOBILE <> 1 order by AID asc", Connection)
Dim ds As New DataSet()
adapter.Fill(ds, "tran")
GridView1.DataSource = ds.Tables("tran").DefaultView
GridView1.DataBind()
Label8.Text = DateTime.Now.ToString("hh:mm:ss tt")
Label7.Text = Date.Now.ToString("M/d/yyyy")
For i = 0 To GridView1.Rows.Count - 1
Using sqlCommand As New SqlCommand()
Label10.Text = GridView1.Rows(0).Cells(0).Text.ToString
End Using
Next
End Sub
Protected Sub OnPageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
End Class