Link to home
Start Free TrialLog in
Avatar of Nugs
Nugs

asked on

Argument not specified for parameter 'e' of 'Public Sub BindData(sender As Object, e As System.Web.UI.WebControls.DataListItemEventArgs)'.

Man this one is annoying...

I am taking a lesson from the MSDN Library (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsdatalistitemeventargsclasstopic.asp)

I have a checkbox in a datalist that I want to set the checked attribute to true or false depending on the data found in the database for that item.

Initially all I am trying to do here is get the damned checkbox on the page without errors... I am not even looking at the database yet to set the attribute... My problem is with the (sender As Object, e As DataListItemEventArgs) part of the code found on the MSDN page above...

Here is my code:

--------------------------------------------------------------------------------------------------------------------------------------------------------------

Sub Page_Load(sender As Object, e As EventArgs)
      If NOT Page.IsPostback
            BindData()
      End If
End Sub

Sub BindData(sender As Object, e As DataListItemEventArgs)
      Dim oleConn As New OleDb.OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_TDGDBConn"))
      Dim oleComm AS NEW OleDb.oleDbCommand()
            oleComm.Connection=oleConn
            oleConn.Open()
      Dim DAChk As New OleDbDataAdapter("SELECT *  FROM TBL_Specials", oleConn )
      Dim DSChk As New DataSet()
            DAChk.Fill(DSChk)      
            
            Try
            If Request.QueryString("DelID") <> "" And CStr(DSChk.Tables(0).Rows.Count) > 8 Then            
                oleComm.CommandText = "DELETE From TBL_Specials Where ID=" & Request.QueryString("DelID")
                oleComm.ExecuteNonQuery()
                lblMsg.Text = "Special #" & Request.QueryString("delid") & " deleted!"
                        lblRecCount.Visible = "false"
            Else
                        lblRecCount.Text = "There need to be at least 8 specials. Please add more before you can delete any."             
                        lblRecCount.Visible = "true"
        End If
            If Request.QueryString("DelID") = "" Then
                  lblRecCount.Visible = "false"
            End If
            Catch ex As Exception
            lblMsg.Text = ex.Message
            End Try            

      Dim da as New OleDb.OleDbDataAdapter()
      Dim ds as New DataSet()
            da.selectCommand=Olecomm
      
            oleComm.CommandText="SELECT * FROM TBL_Specials  ORDER BY Fld_SailDate ASC"
            da.Fill(ds,"Specials")
            DL_Specials.datasource=ds.Tables("Specials")
            DL_Specials.DataBind()                  
            
            'chkNewsletter
            
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim chkNewsletter As CheckBox = CType(e.Item.FindControl("chkNewsletter"), CheckBox)

            Dim Price As String = "True"  
            chkNewsletter.Checked = Price

        End If            
      
            oleConn.Close()
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------------------------


I get this error among others, all normally to do with the e declaration:

--------------------------------------------------------------------------------------------------------------------------------------------------------------
Compiler Error Message: BC30455: Argument not specified for parameter 'e' of 'Public Sub BindData(sender As Object, e As System.Web.UI.WebControls.DataListItemEventArgs)'.

Source Error:


Line 19:       If NOT Page.IsPostback
Line 20:             CleanData()
Line 21:             BindData()
Line 22:       End If
Line 23: End Sub


I think I do not understand the (sender As Object, e As EventArgs) and (sender As Object, e As DataListItemEventArgs) parts of the page…

I need some help here bad…

Nugs
Avatar of michaelitrn
michaelitrn

The issues causing you current error is:

Sub BindData(sender As Object, e As DataListItemEventArgs)

this should be:

Sub BindData()

In addition you need to remove:

  If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim chkNewsletter As CheckBox = CType(e.Item.FindControl("chkNewsletter"), CheckBox)

            Dim Price As String = "True"
            chkNewsletter.Checked = Price

        End If


This code will go in the datalist item_bound event

Avatar of Nugs

ASKER

Ok well if i remove the items you listed my code will be back to what it originaly was. So let me rephrase my question maybe...

I have a datalist that displays items out of the datatbase. In this database there is a field with a true or false value (Fld_Newsletter)...

What I am trying to occomplish here is to display a checkbox for each listing in the datalist, if the value in the database is "True" then the checkbox control is checked. That is all I am looking to do.

I found this code at the MSDN Library that applies a value to a lable that is inside a datalist or grid, I forget. This is the same concept of what I am trying to do.

In terms of the code I posted above, I guess (Although it is used everywhere) I do not understand what the 'e' variable is or what a DataListItemEventArgs is really and how this plays out in the code within the sub.

So I guess my question is two-fold...

1) I would like some help accessing a CheckBox control within a datalist.
and
2) It would probably help if I had a brief explaination of 'e' and 'DataListItemEventArgs'

Nugs
Avatar of Nugs

ASKER

I finally accessed the checkbox control, my databind sub now looks like this:

Sub BindData()
      Dim oleConn As New OleDb.OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_TDGDBConn"))
      Dim oleComm AS NEW OleDb.oleDbCommand()
            oleComm.Connection=oleConn
            oleConn.Open()
      Dim DAChk As New OleDbDataAdapter("SELECT *  FROM TBL_Specials", oleConn )
      Dim DSChk As New DataSet()
            DAChk.Fill(DSChk)      
            
            Try
            If Request.QueryString("DelID") <> "" And CStr(DSChk.Tables(0).Rows.Count) > 8 Then            
                oleComm.CommandText = "DELETE From TBL_Specials Where ID=" & Request.QueryString("DelID")
                oleComm.ExecuteNonQuery()
                lblMsg.Text = "Special #" & Request.QueryString("delid") & " deleted!"
                        lblRecCount.Visible = "false"
            Else
                        lblRecCount.Text = "There need to be at least 8 specials. Please add more before you can delete any."             
                        lblRecCount.Visible = "true"
        End If
            If Request.QueryString("DelID") = "" Then
                  lblRecCount.Visible = "false"
            End If
            Catch ex As Exception
            lblMsg.Text = ex.Message
            End Try            

      Dim da as New OleDb.OleDbDataAdapter()
      Dim ds as New DataSet()
            da.selectCommand=Olecomm
      
            oleComm.CommandText="SELECT * FROM TBL_Specials  ORDER BY Fld_SailDate ASC"
            da.Fill(ds,"Specials")
            DL_Specials.datasource=ds.Tables("Specials")
            DL_Specials.DataBind()                  
            
            'chkNewsletter            
            
        Dim I As Long
          For I=0 To DL_Specials.Items.Count -1
              Dim CurrentCheckBox As CheckBox
              CurrentCheckBox = DL_Specials.Items(I).FindControl("chkNewsletter")
                    CurrentCheckBox.Checked = ds.Tables("Specials").Rows(I).Item("Fld_Newsletter").ToString()
                    'Response.Write(ds.Tables("Specials").Rows(I).Item("Fld_Newsletter").ToString())
          Next            
      
            oleConn.Close()
End Sub





I would still like a explaination of the 'e' and 'DataListItemEventArgs' and what it is for?!

Nugs
ASKER CERTIFIED SOLUTION
Avatar of michaelitrn
michaelitrn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial