i want to display some data in a grid but this is the error i get.

withEvents variable 'DataGrid1' implicitly defines '_DataGrid1', which conflicts with a member of the same name in class 'mastersearch'.

i tried renaming the variables but that does not help because it EITHER doesnt bind the data at all OR does bind it but doesnt trigger the page change event

this is the code if it helps
thanks in advance

Public Class mastersearch
    Inherits Page

    ' Methods
    Public Sub New()
        AddHandler MyBase.Init, New EventHandler(AddressOf Me.Page_Init)
        AddHandler MyBase.Load, New EventHandler(AddressOf Me.Page_Load)
        Me.qry = ""
    End Sub

    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As DataGridPageChangedEventArgs)
        Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
        Me.doSearch()
    End Sub

    Public Sub doSearch()
        Try
            Me.DataView1.RowFilter = Me.Session.Item("qry").ToString
            Me.OleDbDataAdapter1.Fill(Me.DataSet21.Tables.Item(0))
            Me.Response.Write(("<b>" & StringType.FromInteger(Me.DataView1.Count) & " records found.</b><p>"))
            Me.DataGrid1.DataBind()
        Catch exception2 As Exception
            ProjectData.SetProjectError(exception2)
            Dim exception1 As Exception = exception2
            Me.Response.Write(("Could not perform search, please try again" & ChrW(13) & "<!-- " & exception1.Message & "-->"))
            ProjectData.ClearProjectError()
        End Try
    End Sub

    <DebuggerStepThrough()> _
    Private Sub InitializeComponent()

.....parameters and declarations not shown here ......

    Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        Me.InitializeComponent()
    End Sub

    Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not Me.IsPostBack Then
            Dim text1 As String = Me.Request.Item("_mode")
            If (Not Me.Request.Item("_dir") Is Nothing) Then
                Me.qry = ("surname like '" & Me.Request.Item("_dir") & "%'")
            ElseIf ((Not text1 Is Nothing) AndAlso (StringType.StrCmp(text1, "adv", False) = 0)) Then
                Dim num2 As Integer = (Me.Request.Form.Count - 1)
                Dim num1 As Integer = 0
                Do While (num1 <= num2)
                    If Not Me.Request.Form.Keys.Item(num1).StartsWith("_") Then
                        If (StringType.StrCmp(Me.qry, "", False) <> 0) Then
                            Me.qry = (Me.qry & " AND ")
                        End If
                        Dim textArray1 As String() = New String() {Me.qry, "[", Me.Request.Form.Keys.Item(num1), "] like '%", Me.Request.Form.Item(num1), "%' "}
                        Me.qry = String.Concat(textArray1)
                    End If
                    num1 += 1
                Loop
            End If
            Me.Session.Item("qry") = Me.qry
            Me.doSearch()
        End If
    End Sub


    ' Properties
    Protected Overridable Property DataGrid1() As DataGrid
        Get
            Return Me._DataGrid1
        End Get
        Set(ByVal WithEventsValue As DataGrid)
            If (Not Me._DataGrid1 Is Nothing) Then
                RemoveHandler Me._DataGrid1.PageIndexChanged, New DataGridPageChangedEventHandler(AddressOf Me.DataGrid1_PageIndexChanged)
            End If
            Me._DataGrid1 = WithEventsValue
            If (Not Me._DataGrid1 Is Nothing) Then
                AddHandler Me._DataGrid1.PageIndexChanged, New DataGridPageChangedEventHandler(AddressOf Me.DataGrid1_PageIndexChanged)
            End If
        End Set
    End Property

    Protected Overridable Property DataSet21() As DataSet2
        Get
            Return Me._DataSet21
        End Get
        Set(ByVal WithEventsValue As DataSet2)
            If (Not Me._DataSet21 Is Nothing) Then
            End If
            Me._DataSet21 = WithEventsValue
            If (Not Me._DataSet21 Is Nothing) Then
            End If
        End Set
    End Property

    Protected Overridable Property DataView1() As DataView
        Get
            Return Me._DataView1
        End Get
        Set(ByVal WithEventsValue As DataView)
            If (Not Me._DataView1 Is Nothing) Then
            End If
            Me._DataView1 = WithEventsValue
            If (Not Me._DataView1 Is Nothing) Then
            End If
        End Set
    End Property

    Protected Overridable Property OleDbConnection1() As OleDbConnection
        Get
            Return Me._OleDbConnection1
        End Get
        Set(ByVal WithEventsValue As OleDbConnection)
            If (Not Me._OleDbConnection1 Is Nothing) Then
            End If
            Me._OleDbConnection1 = WithEventsValue
            If (Not Me._OleDbConnection1 Is Nothing) Then
            End If
        End Set
    End Property

    Protected Overridable Property OleDbDataAdapter1() As OleDbDataAdapter
        Get
            Return Me._OleDbDataAdapter1
        End Get
        Set(ByVal WithEventsValue As OleDbDataAdapter)
            If (Not Me._OleDbDataAdapter1 Is Nothing) Then
            End If
            Me._OleDbDataAdapter1 = WithEventsValue
            If (Not Me._OleDbDataAdapter1 Is Nothing) Then
            End If
        End Set
    End Property

    Protected Overridable Property OleDbDeleteCommand1() As OleDbCommand
        Get
            Return Me._OleDbDeleteCommand1
        End Get
        Set(ByVal WithEventsValue As OleDbCommand)
            If (Not Me._OleDbDeleteCommand1 Is Nothing) Then
            End If
            Me._OleDbDeleteCommand1 = WithEventsValue
            If (Not Me._OleDbDeleteCommand1 Is Nothing) Then
            End If
        End Set
    End Property

    Protected Overridable Property OleDbInsertCommand1() As OleDbCommand
        Get
            Return Me._OleDbInsertCommand1
        End Get
        Set(ByVal WithEventsValue As OleDbCommand)
            If (Not Me._OleDbInsertCommand1 Is Nothing) Then
            End If
            Me._OleDbInsertCommand1 = WithEventsValue
            If (Not Me._OleDbInsertCommand1 Is Nothing) Then
            End If
        End Set
    End Property

    Protected Overridable Property OleDbSelectCommand1() As OleDbCommand
        Get
            Return Me._OleDbSelectCommand1
        End Get
        Set(ByVal WithEventsValue As OleDbCommand)
            If (Not Me._OleDbSelectCommand1 Is Nothing) Then
            End If
            Me._OleDbSelectCommand1 = WithEventsValue
            If (Not Me._OleDbSelectCommand1 Is Nothing) Then
            End If
        End Set
    End Property

    Protected Overridable Property OleDbUpdateCommand1() As OleDbCommand
        Get
            Return Me._OleDbUpdateCommand1
        End Get
        Set(ByVal WithEventsValue As OleDbCommand)
            If (Not Me._OleDbUpdateCommand1 Is Nothing) Then
            End If
            Me._OleDbUpdateCommand1 = WithEventsValue
            If (Not Me._OleDbUpdateCommand1 Is Nothing) Then
            End If
        End Set
    End Property


    ' Fields
    <AccessedThroughProperty("DataGrid1")> _
    Public _DataGrid1 As DataGrid
    <AccessedThroughProperty("DataSet21")> _
    Private _DataSet21 As DataSet2
    <AccessedThroughProperty("DataView1")> _
    Private _DataView1 As DataView
    <AccessedThroughProperty("OleDbConnection1")> _
    Private _OleDbConnection1 As OleDbConnection
    <AccessedThroughProperty("OleDbDataAdapter1")> _
    Private _OleDbDataAdapter1 As OleDbDataAdapter
    <AccessedThroughProperty("OleDbDeleteCommand1")> _
    Private _OleDbDeleteCommand1 As OleDbCommand
    <AccessedThroughProperty("OleDbInsertCommand1")> _
    Private _OleDbInsertCommand1 As OleDbCommand
    <AccessedThroughProperty("OleDbSelectCommand1")> _
    Private _OleDbSelectCommand1 As OleDbCommand
    <AccessedThroughProperty("OleDbUpdateCommand1")> _
    Private _OleDbUpdateCommand1 As OleDbCommand
    Private qry As String
End Class

I think it might be that you can't have a DataGrid1 object variable AND a DataGrid1 property method.

Protected Overridable Property DataGrid1() As DataGrid
Get
Return Me._DataGrid1
End Get

That smells to me, surely this should be something like GetDataGrid()

Please use code tags, it's very hard to read your code without them and that puts people off bothering to help. See that link 'the basics' in my signature ? take a look all the details are there.

was my first post with codes so didnt know how to do it

GetDataGrid doesnt help

may be because i dont know how to use it

could any body please explain it to me

this is the error message

Compiler Error Message: BC31060: withEvents variable 'DataGrid1' implicitly defines '_DataGrid1', which conflicts with a member of the same name in class 'mastersearch'


may be i need something that allows the use of variable 'DataGrid1' more than once or so

I Think you are inheriting from another page called mastersearch which also has a DataGrid1 member, you should not just accept the default variable names that VS gives you they should be meaningful. Change the DataGrid's ID to something like dgSearchResults or something like that.

The protected keyword means the member variable is available to derived classes, private member variables would not be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.