Pass Parameter to Subroutine in Codebehind

Posted by Sanjubaba on Stack Overflow See other posts from Stack Overflow or by Sanjubaba
Published on 2010-05-29T06:23:53Z Indexed on 2010/05/29 6:32 UTC
Read the original article Hit count: 256

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-2.0