我试图在我的代码隐藏中将活动的标识(RefNum)传递给Sub。我知道我应该在将参数传递给子例程和方法时使用括号,并且我尝试了很多方法并且一直收到以下错误:在Codebehind中将参数传递给子例程
BC30203:预期标识符。
我在前端硬编码它只是为了让它通过[OnDataBound =“FillSectorCBList(”“”WK.002“”“)”],但它显然是错误的。 :(
前端:
<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>
代码隐藏:
子FillSectorCBList(BYVAL引用句柄作为字符串,BYVAL发件人作为对象,BYVALË作为System.EventArgs) 昏暗SectorIDs作为新列表项
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
任何意见将是巨大的。我不知道如果我甚至有正确的方法。
谢谢!