justnew
04-14-2005, 10:03 AM
Hi All
Can somebody help me. I have a datagrid with hyperlink-column. the aim of this column is to retrieve the information about the product in the datagrid based on the ProductID. That works great. The problem I am having is that the datagrid have pages 1 2 3 4 now when I am in page 2 or 3 and I click on the hyperlink-column to display the information, it display correctly as well but it will automatically takes me to the first page that's page 1.
Any help welcome
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindSQL()
End If
ProductInfo()
Sub ProductInfo()
Dim connString As String = "Server="Server=mysqlserver; Initial Catalog=mydb; UID=myUID; Password=mypwd; Network Library=dbmssocn;"
ProductId = Request.QueryString("ProductId")
ds = GetProductID(ProductId)
'BindSQL()
If ds.Tables(0).Rows.Count > 0 Then
datarad = ds.Tables(0).Rows(0)
lblfname.Text = datarad.Item(0)
lblphone.Text = datarad.Item(1)
lbltown.Text = datarad.Item(3)
lblcomputer.Text = datarad.Item(4)
lbldescription.Text = datarad.Item(6)
lblprice.Text = datarad.Item(7)
End If
End Sub
Sub Repage(ByVal sender As Object, ByVal e As EventArgs)
dgImages.CurrentPageIndex = 0
BindSQL()
End Sub
Sub BindSQL()
Dim MyConnection As SqlConnection
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim sqlStr As String = "SELECT Product.CategoryID, Product.Product,Product.ProductID, Product.SellerID, Product.Price, Product.Descriptions,Product_Image.ImageID,Product_Image.ProductID, Product_Image.LGimgname, Product_Image.LGimgdata,Product_Image.LGimgcontenttype, Product_Image.SMimgname, Product_Image.SMimgdata, Product_Image.SMimgcontenttype, Product_Image.UploadDate FROM Product INNER JOIN Product_Image ON Product.ProductID = Product_Image.ProductID where CategoryID = 2 Order by Price asc"
Dim strConn As String = "Server="Server=mysqlserver; Initial Catalog=mydb; UID=myUID; Password=mypwd; Network Library=dbmssocn;"
Dim RcdCount As Integer
'Open up our connection with our connection object
MyConnection = New SqlConnection(strConn)
'To execute our Sql Statement and provide out active connection
MyCommand = New SqlDataAdapter(sqlStr, MyConnection)
'Create instance of dataset object and fill our predetermined datagrid with it and we name it
DS = New DataSet
MyCommand.Fill(DS, "Product")
RcdCount = DS.Tables("Product").Rows.Count.ToString()
'dgImages.PageSize = CInt(ps.SelectedItem.Value)
If Not Page.IsPostBack Then
dgImages.CurrentPageIndex = 0
End If
ResultCount = RcdCount
RecordCount.Text = "<b><font color=red>" & RcdCount & "</font> records found"
'Now we assign the dataview to the datasource of the datagrid and we send it right on it
Try
dgImages.DataSource = DS
dgImages.DataBind()
Catch e As Exception
dgImages.CurrentPageIndex = 0
End Try
lblPageCount.Text = "Page " & dgImages.CurrentPageIndex + 1 & " of " & dgImages.PageCount
End Sub
Private Sub dgImages_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgImages.PageIndexChanged
dgImages.CurrentPageIndex = e.NewPageIndex
BindSQL()
End Sub
Sub ShowStats()
lblCurrentIndex.Text = "CurrentPageIndex is " & dgImages.CurrentPageIndex
lblPageCount.Text = "PageCount is " & dgImages.PageCount
End Sub
Function FormatURL(ByVal strArgument) As String
Return ("ReadImages.aspx?id=" & strArgument)
End Function
Public Function GetProductID(ByVal ProductId As Integer) As DataSet
Dim sql As String
sql = "exec ProductSellerInfo " & ProductId
Dim connString As String = "Server=mysqlserver; Initial Catalog=mydb; UID=myUID; Password=mypwd; Network Library=dbmssocn;"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Dim ds As DataSet = New DataSet
conn.Open()
Try
' forsøk noe kode
da.Fill(ds, "Product")
Return ds
Catch e As SqlException
'fang feil og gjør noe
'MsgBox(strsql)
Throw (e)
Finally
'rydd opp
conn.Close()
End Try
End Function
Can somebody help me. I have a datagrid with hyperlink-column. the aim of this column is to retrieve the information about the product in the datagrid based on the ProductID. That works great. The problem I am having is that the datagrid have pages 1 2 3 4 now when I am in page 2 or 3 and I click on the hyperlink-column to display the information, it display correctly as well but it will automatically takes me to the first page that's page 1.
Any help welcome
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindSQL()
End If
ProductInfo()
Sub ProductInfo()
Dim connString As String = "Server="Server=mysqlserver; Initial Catalog=mydb; UID=myUID; Password=mypwd; Network Library=dbmssocn;"
ProductId = Request.QueryString("ProductId")
ds = GetProductID(ProductId)
'BindSQL()
If ds.Tables(0).Rows.Count > 0 Then
datarad = ds.Tables(0).Rows(0)
lblfname.Text = datarad.Item(0)
lblphone.Text = datarad.Item(1)
lbltown.Text = datarad.Item(3)
lblcomputer.Text = datarad.Item(4)
lbldescription.Text = datarad.Item(6)
lblprice.Text = datarad.Item(7)
End If
End Sub
Sub Repage(ByVal sender As Object, ByVal e As EventArgs)
dgImages.CurrentPageIndex = 0
BindSQL()
End Sub
Sub BindSQL()
Dim MyConnection As SqlConnection
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim sqlStr As String = "SELECT Product.CategoryID, Product.Product,Product.ProductID, Product.SellerID, Product.Price, Product.Descriptions,Product_Image.ImageID,Product_Image.ProductID, Product_Image.LGimgname, Product_Image.LGimgdata,Product_Image.LGimgcontenttype, Product_Image.SMimgname, Product_Image.SMimgdata, Product_Image.SMimgcontenttype, Product_Image.UploadDate FROM Product INNER JOIN Product_Image ON Product.ProductID = Product_Image.ProductID where CategoryID = 2 Order by Price asc"
Dim strConn As String = "Server="Server=mysqlserver; Initial Catalog=mydb; UID=myUID; Password=mypwd; Network Library=dbmssocn;"
Dim RcdCount As Integer
'Open up our connection with our connection object
MyConnection = New SqlConnection(strConn)
'To execute our Sql Statement and provide out active connection
MyCommand = New SqlDataAdapter(sqlStr, MyConnection)
'Create instance of dataset object and fill our predetermined datagrid with it and we name it
DS = New DataSet
MyCommand.Fill(DS, "Product")
RcdCount = DS.Tables("Product").Rows.Count.ToString()
'dgImages.PageSize = CInt(ps.SelectedItem.Value)
If Not Page.IsPostBack Then
dgImages.CurrentPageIndex = 0
End If
ResultCount = RcdCount
RecordCount.Text = "<b><font color=red>" & RcdCount & "</font> records found"
'Now we assign the dataview to the datasource of the datagrid and we send it right on it
Try
dgImages.DataSource = DS
dgImages.DataBind()
Catch e As Exception
dgImages.CurrentPageIndex = 0
End Try
lblPageCount.Text = "Page " & dgImages.CurrentPageIndex + 1 & " of " & dgImages.PageCount
End Sub
Private Sub dgImages_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgImages.PageIndexChanged
dgImages.CurrentPageIndex = e.NewPageIndex
BindSQL()
End Sub
Sub ShowStats()
lblCurrentIndex.Text = "CurrentPageIndex is " & dgImages.CurrentPageIndex
lblPageCount.Text = "PageCount is " & dgImages.PageCount
End Sub
Function FormatURL(ByVal strArgument) As String
Return ("ReadImages.aspx?id=" & strArgument)
End Function
Public Function GetProductID(ByVal ProductId As Integer) As DataSet
Dim sql As String
sql = "exec ProductSellerInfo " & ProductId
Dim connString As String = "Server=mysqlserver; Initial Catalog=mydb; UID=myUID; Password=mypwd; Network Library=dbmssocn;"
Dim conn As SqlConnection = New SqlConnection(connString)
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Dim ds As DataSet = New DataSet
conn.Open()
Try
' forsøk noe kode
da.Fill(ds, "Product")
Return ds
Catch e As SqlException
'fang feil og gjør noe
'MsgBox(strsql)
Throw (e)
Finally
'rydd opp
conn.Close()
End Try
End Function