views:

26

answers:

3

I'm trying to pass an ID of an activity (RefNum) to a Sub in my codebehind. I know I'm supposed to use parentheses when passing parameters to subroutines and methods, and I've tried a number of ways and keep receiving the following error:

BC30203: Identifier expected.

I'm hard-coding it on the front-end just to try to get it to pass [ OnDataBound="FillSectorCBList("""WK.002""")" ], but it's obviously wrong. :(

Front-end:

<asp:DetailsView ID="dvEditActivity"  AutoGenerateRows="False" DataKeyNames="RefNum" OnDataBound="dvSectorID_DataBound" OnItemUpdated="dvEditActivity_ItemUpdated" DataSourceID="dsEditActivity" >
   <Fields>
      <asp:TemplateField>  
                <ItemTemplate>
                    <br /><span style="color:#0e85c1;font-weight:bold">Sector</span><br /><br />
                    <asp:CheckBoxList ID="cblistSector" runat="server" DataSourceID="dsGetSectorNames" DataTextField="SectorName" DataValueField="SectorID" OnDataBound="FillSectorCBList("""WK.002""")" ></asp:CheckBoxList>
                    <%-- Datasource to populate cblistSector --%>
                    <asp:SqlDataSource ID="dsGetSectorNames" runat="server" ConnectionString="<%$ ConnectionStrings:dbConn %>" ProviderName="<%$ ConnectionStrings:dbConn.ProviderName %>" SelectCommand="SELECT SectorID, SectorName from Sector ORDER BY SectorID"></asp:SqlDataSource>
                </ItemTemplate>
              </asp:TemplateField>
  </Fields>
</asp:DetailsView>

Code-behind:

Sub FillSectorCBList(ByVal RefNum As String, ByVal sender As Object, ByVal e As System.EventArgs) Dim SectorIDs As New ListItem

    Dim myConnection As String = ConfigurationManager.ConnectionStrings("dbConn").ConnectionString()
    Dim objConn As New SqlConnection(myConnection)
    Dim strSQL As String = "SELECT DISTINCT A.RefNum, AS1.SectorID, S.SectorName FROM Activity A LEFT OUTER JOIN Activity_Sector AS1 ON AS1.RefNum = A.RefNum LEFT OUTER JOIN Sector S ON AS1.SectorID = S.SectorID WHERE A.RefNum = @RefNum ORDER BY A.RefNum"
    Dim objCommand As New SqlCommand(strSQL, objConn)
    objCommand.Parameters.AddWithValue("RefNum", RefNum)

    Dim ad As New SqlDataAdapter(objCommand)

    Try
       [Code]
    Finally
       [Code]
    End Try

    objCommand.Connection.Close()
    objCommand.Dispose()
    objConn.Close()
End Sub

Any advice would be great. I'm not sure if I even have the right approach.

Thank you!

+1  A: 

You can't pass a parameter to the OnDataBound event method. The method has to follow a specific signature. Since this parameter is essentially a program constant, I would just code it into the method or read it in from somewhere. You could also, of course, have the method that handles the event just call a different method that accepts your parameter.

Joel Coehoorn
+1  A: 

Change your

OnDataBound="FillSectorCBList("""WK.002""")"

to

OnDataBound='FillSectorCBList("WK.002")' 

While this would take care of the Identifier expected error it would most likely lead to another as Joel posted before I could submit.

Gthompson83
A: 

As the others posted, do you can't use the OnDataBound event for that purpose. You need to set the DataSource property to your desired method.

DataSource='FillSectorCBList("WK.002")'

Be aware, that you can't set the DataSource and the DataSourceID property at the same time. You maybe need to perform a manually .DataBind() as well.

citronas