Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello programmers, as you see i want a paging on my gridvew. the problem is it doesnt work. Plss help
My Codes:
VB
Imports System.data
Imports System.Data.Sqlclient
Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim boom As String = Session("title")
        title.Text = boom
        lbtitle.Text = title.Text
       End Sub
    Protected Sub gridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
        GridView1.PageIndex = e.NewPageIndex
        binddata()    
End Sub
    Public Sub binddata()
        Dim str As String
        Dim con As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        con.Open()
        str = "Select [addon],[username] from [tblForums] where ([title]=@title)"
        Dim command As SqlCommand = New SqlCommand(Str, con)
        command.Parameters.AddWithValue("@title", title.Text)
        GridView1.DataSource = command.ExecuteReader
        GridView1.DataBind()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        wew()
    End Sub
    Public Sub wew()
        Dim str As String
        Dim con As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        con.Open()
        str = "INSERT INTO [tblForums](title, username,addon) VALUES (@title, @username,  @addon)"
        Dim command As SqlCommand = New SqlCommand(str, con)
        command.Parameters.Add("@title", SqlDbType.NVarChar).Value = lbtitle.Text
        command.Parameters.Add("@username", SqlDbType.NChar).Value = tbname.Text
        command.Parameters.Add("@addon", SqlDbType.NVarChar).Value = text.Text
        command.ExecuteNonQuery()

    End Sub
Posted
Updated 26-Jul-11 17:32pm
v2

Hi,
use this it will work fine.
actually u have to call binddata() in pageindexchanging event


VB
Imports System.data
Imports System.Data.Sqlclient
Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim boom As String = Session("title")
        title.Text = boom
        lbtitle.Text = title.Text
        binddata()
    End Sub
    Protected Sub gridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
        GridView1.PageIndex = e.NewPageIndex
        binddata()
    End Sub
    Public Sub binddata()
        Dim str As String
        Dim con As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        con.Open()
        str = "Select [addon],[username] from [tblForums] where ([title]=@title)"
        Dim command As SqlCommand = New SqlCommand(Str, con)
        command.Parameters.AddWithValue("@title", title.Text)
        GridView1.DataSource = command.ExecuteReader
        GridView1.DataBind()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        wew()
    End Sub
    Public Sub wew()
        Dim str As String
        Dim con As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        con.Open()
        str = "INSERT INTO [tblForums](title, username,addon) VALUES (@title, @username,  @addon)"
        Dim command As SqlCommand = New SqlCommand(str, con)
        command.Parameters.Add("@title", SqlDbType.NVarChar).Value = lbtitle.Text
        command.Parameters.Add("@username", SqlDbType.NChar).Value = tbname.Text
        command.Parameters.Add("@addon", SqlDbType.NVarChar).Value = text.Text
        command.ExecuteNonQuery()

    End Sub.
 
Share this answer
 
Comments
drkterror 26-Jul-11 23:19pm    
sir now the gridview doesnt work meaning i think it doesnt bind
Tajuddin_HYD 26-Jul-11 23:32pm    
r u getting any error while using above code again?
drkterror 26-Jul-11 23:33pm    
sir ive modified my code just what you said but now it doesnt bind
place ur bindData() in ispostback condition in page load and try once,
it will work...

If Not IsPostBack Then

binddata()

End If
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900