Я поддерживаю старое приложение, и мне нужно изменить раскрывающийся список на список, чтобы пользователи могли выбирать несколько элементов. Когда я пытаюсь получить элементы списка в коде, я получаю сообщение об ошибке 'ddlCourse' is not declared. It may be inaccessible due to its protection level.
.aspx веб-страница:
<obout:DetailGrid
runat="server"
ID="grid2"
AutoGenerateColumns="false"
AllowAddingRecords="true"
ShowFooter="true"
PageSize="10"
DataSourceID="dsCertTrn"
FolderStyle="~/styles/bgGrid"
ForeignKeys="CertInstId"
OnInsertCommand="InsertCourse"
OnDeleteCommand="DeleteCourse"
OnUpdateCommand="UpdateCourse">
<ClientSideEvents ExposeSender="true" OnClientPopulateControls="onPopulateControls" />
<MasterDetailSettings LoadingMode="OnLoad" ShowEmptyDetails="false" />
<Columns>
<obout:Column DataField="CertCourseId" ReadOnly="false" HeaderText="Topics Instructor Is Qualified To Provide Training For" Width="500" Visible="true">
<TemplateSettings TemplateID="gtCertCourse" EditTemplateID="gtEditCourse" />
</obout:Column>
<obout:Column ID="Column1" AllowEdit="true" AllowDelete="true" HeaderText="" Width="225" />
<obout:Column DataField="Id" HeaderText="Id" ReadOnly="false" Visible="false" Width = "75"></obout:Column>
<obout:Column DataField="CertInstId" HeaderText="Inst Id" ReadOnly="false" Visible="false" Width = "75"></obout:Column>
</Columns>
<TemplateSettings NewRecord_TemplateId="addTemplate2" NewRecord_EditTemplateId="saveTemplate2" />
<Templates>
<obout:GridTemplate runat="server" ID="saveTemplate2">
<Template>
<input type="button" id="btnSave" value="Save" class="tdTextSmall" onclick="<%# Container.GridClientID %>.insertRecord()"/>
|
<input type="button" id="btnCancel" value="Cancel" class="tdTextSmall" onclick="<%# Container.GridClientID %>.cancelNewRecord()"/>
</Template>
</obout:GridTemplate>
<obout:GridTemplate runat="server" ID="gtCertCourse" >
<Template>
<%# Container.DataItem("Course")%>
</Template>
</obout:GridTemplate>
<obout:GridTemplate
runat="server"
ID="gtEditCourse"
ControlID="ddlCourse"
ControlPropertyName="value">
<Template>
<asp:ListBox
ID="ddlCourse"
Rows="18"
Width="99%"
SelectionMode="Multiple"
runat="server"
AppendDataBoundItems="True"
DataSourceID="dsCourses"
CssClass="ob_gEC"
DataTextField="Course"
DataValueField="CertCourseId">
<asp:ListItem Text="Select course(s) (hold ctrl to select multiple)" Value="" Selected="True" />
<asp:ListItem Text="Administrative" Value = "133" />
<asp:ListItem Text=" - Civil Rights and Civil Liability" Value = "59" />
<asp:ListItem Text=" - U.S. Constitutional Authority " Value = "110"/>
<asp:ListItem Text=" - Juvenile Law and Processing " Value = "88" />
<asp:ListItem Text=" - Laws of Admission " Value = "89" />
<asp:ListItem Text=" - Rights of the Accused " Value = "101"/>
<asp:ListItem Text=" - Rules of Evidence " Value = "102"/>
<asp:ListItem Text=" - Use of Force" Value = "111"/>
</asp:ListBox>
<asp:SqlDataSource ID="dsCourses" runat="server"
ConnectionString="<%$ ConnectionStrings:NameOfConnectionString %>"
SelectCommand="SELECT [CertCourseId], [Course] FROM database ORDER BY [Course]" >
</asp:SqlDataSource>
</Template>
</obout:GridTemplate>
</Templates>
Код сзади:
Protected Sub InsertCourse(ByVal sender As Object, ByVal e As GridRecordEventArgs) Handles grid2.InsertCommand
Dim sqlConn As SqlConnection = New SqlConnection(strConnString)
sqlConn.Open()
Dim msg As String
Dim li As ListItem
msg = ""
For Each li In ddlCourse.Items
If li.Selected = True Then
msg = msg & "<br>" & li.Text & " selected."
End If
Next
End Sub
Я получаю ошибку в коде за страницей в For Each
l oop. Я попытался передать ListBox в качестве дополнительного параметра, но, похоже, InsertCommand
допускает только 2 параметра. Любые предложения будут оценены.