ASP.NET 2.0 ProfessionalIf you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Would you know if there is a way of sharing my initial DataSet of data (that I used to fill the Gridview in the first place) between classes as I would like to set up sorting as a separate class but can't see how unless I go through using the DataAdapter.fill again.
Tell me if I am making this harder than it should be.. I am sort of going with instinct here.
Hi,
Write a simple class with a method which returns dataset.U can fill dataset here and return that dataset.
Now U can use(Share) this dataset by calling this method whnever u want the dataset
class simpleclass{
public static System.Data.Dataset GetProducts()
{
--do data access ,fill the dataset---
return ds;
I know I am really close to having this sorted!.. I have re-used my class which produces the initial dataset (called dbconnection for this example) within my Sorting class as described in your kind response. But this produces the following error:
ExecuteReader: CommandText property has not been initialized
This error refers to the following line within my code within the class dbconnection:
myDataAdapter.Fill(MyDataSet, "reporttbl")
I can't seem to get my head around how to resolve this. Would you have any ideas?
HIIII....IM HAVING PROBLEM IN SORTING GRIDVIEW THE ERROR MESSAGE IS LIKE...
the gridview 'GRIDVIEW1' fired event sorting which wasn't handled
I TRIED TO BIND GRID IN GRIDVIEW_SORTING EVENT...
BUT STILL IT NOT WORKS...MY CODE LIKE
Imports System.Data.OleDb
Imports System.IO
Imports System.Web.UI.Design
Imports System.Data
Imports PublicFunctions
Imports Microsoft.VisualBasic.Interaction
Imports Microsoft.VisualBasic.MsgBoxStyle
Public Class empsearch
Inherits System.Web.UI.Page
Dim conn As New OleDbConnection
Dim da As New OleDbDataAdapter
Dim cmd As New OleDbCommand
Dim reader As OleDbDataReader
Dim ds As New DataSet
Dim constr As String
Dim dbpath As String
Dim p As PublicFunctions = New PublicFunctions
Dim str As String
Dim loginname As String
Public Shared fields4(11) As String
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
formfill()
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim Code As String = GridView1.SelectedRow.Cells(1).Text
If (Request.QueryString("name") = "edit") Then
Response.Redirect("~/empedit.aspx?Code=" & Code & "&LoginId=" & loginname)
ElseIf (Request.QueryString("name") = "delete") Then
Response.Redirect("~/empdelete.aspx?Code=" & Code & "&LoginId=" & loginname)
ElseIf (Request.QueryString("name") = "view") Then
Response.Redirect("~/empview.aspx?Code=" & Code & "&LoginId=" & loginname)
Else
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If (Request.QueryString("name") = "view") Then
' GridView1.AutoGenerateSelectButton = False
'Else
' GridView1.AutoGenerateSelectButton = True
'End If
loginname = Request.QueryString("LoginId")
If (Not IsPostBack) Then
conn = p.GetAccessConn(Me)
Dim Table As String = Request.QueryString("master")
cmd.CommandText = "Select * from " & Table & " "
cmd.Connection = conn
reader = cmd.ExecuteReader
Dim i As Integer
For i = 0 To 10
fields4(i) = ""
Next
For i = 0 To reader.FieldCount - 1
dropfield.Items.Add(reader.GetName(i).ToString)
fields4(i) = (reader.GetName(i).ToString)
If (i = 5) Then
Exit For
End If
Next
lblmsg.Text = " Select " & Table & " record to " & Request.QueryString("name")
reader.Close()
conn.Close()
End If
End Sub
Protected Sub btnsearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsearch.Click
formfill()
End Sub
Sub formfill()
If (Page.IsPostBack = True) Then
lblmsg.Text = ""
p.search("Employee", fields4, "Code", txtsearch.Text)
End If
Dim i As Integer
Dim qry As String
conn = p.GetAccessConn(Me)
Dim Table As String = Request.QueryString("master")
qry = p.search(Table, fields4, dropfield.SelectedValue.ToString, txtsearch.Text)
GridView1.DataSource = p.myoledataset(Me, qry, "employee")
GridView1.DataBind()
For i = 3 To GridView1.Columns.Count - 1
GridView1.Columns(i).Visible = False
Next
conn.Close()
End Sub
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
formfill()
End Sub
End Class