我需要能夠以隱藏從我的動態顯示的BulletedList 2個選項(這是一個DetailsView內建成)。每次我嘗試通過BulletedList編寫一個循環時,我都會收到一個錯誤,說它不是一個集合類型,所以我想我可以遍歷DetailsView來查找要隱藏的項目。通過DetailsView控件循環隱藏動態的BulletedList項目
我不能改變SQL,因爲這個特殊的項目符號列表大幹快上2個不同的頁面中,它只是一個,我只需要顯示與該ID相關聯的4個項目中2。
<asp:TemplateField HeaderText="Answer(s)" SortExpression="PicklistID">
<ItemTemplate>
<asp:HiddenField ID="hiddenPicklistID" runat="server"
Value='<%# Bind("PicklistID") %>' />
<asp:BulletedList ID="blText" runat="server" DataSourceID="dsPicklist"
DataTextField="TEXT">
</asp:BulletedList>
<asp:SqlDataSource ID="dsPicklist" runat="server"
ConnectionString="<%$ ConnectionStrings:SurveyConnectionString %>"
SelectCommand="SELECT p.TEXT FROM PICKLIST p
JOIN C_Survey_Questions c
ON p.PICKLISTID = c.PicklistID
AND c.QuestionID = @QuestionID
AND c.SurveyID = @SurveyID
WHERE p.PICKLISTID IS NOT NULL
AND c.PicklistID IS NOT NULL">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="SurveyID"
PropertyName="SelectedValue" Type="Int32" />
<asp:ControlParameter ControlID="hiddenQuestionID" Name="QuestionID"
PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
我已經試過:
Protected Sub blText_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Dim blText As BulletedList
For Each BulletedListItem In blText
Next
End Sub
但Visual Studio中告訴我,這是不是一個集合類型。所以我想我可以在下面的代碼中添加一個For Each。我不知道如何通過DetailsView循環,有人可以在這裏指出我正確的方向嗎?
Protected Sub dvSurveyQuestions_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dvSurveyQuestions.DataBound
End Sub
更新2/6:我宣佈我的BulletedList使用的FindControl,有沒有更多的錯誤說法的BulletedList未聲明。
Protected Sub blText_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Dim blText As BulletedList = dvSurveyQuestions.FindControl("blText")
For Each i As ListItem In blText.Items
Next
End Sub
另一個更新:我需要得到blText爲33.獨特QuestionID的QuestionID是一個整數,但我不知道如何將HiddenField一個整數字段關聯。在這段代碼中,「是」被強調說Is operator does not accept opeands of type 'Integer.'
所以我改變是一個=並且得到錯誤Operator = is not defined for types HiddenField and Integer.
Dim QuestionID = DirectCast(dvSurveyQuestions.FindControl("hiddenQuestionID"), HiddenField)
If QuestionID Is 33 Then
Dim blText As BulletedList = dvSurveyQuestions.FindControl("blText")
For intCursor = (blText.Items.Count - 1) To 0 Step -1
If blText.Items(intCursor).Text = "Self Directed" Or "Systems" Then
blText.Items.RemoveAt(intCursor)
End If
Next
End If
這是從項目屬性的作品
Dim QuestionID As Integer = CInt(CType(dvSurveyQuestions.FindControl("hiddenQuestionID"), HiddenField).Value)
If QuestionID = 33 Then
Dim blText As BulletedList = dvSurveyQuestions.FindControl("blText")
For intCursor = (blText.Items.Count - 1) To 0 Step -1
If blText.Items(intCursor).Text = "Self Directed" Or blText.Items(intCursor).Text = "Systems" Then
blText.Items.RemoveAt(intCursor)
End If
Next
End If
您正在尋找的HiddenField的Value屬性,從而可以推斷,但在這裏它與鑄造...暗淡QuestionID作爲整數= CINT(CTYPE(dvSurveyQuestions.FindControl( 「hiddenQuestionID」),HiddenField).value的)「如果QuestionID = 33然後 – N0Alias 2012-02-07 01:54:44
謝謝!這幫了很多忙。 – jlg 2012-02-07 14:55:46