首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >循环遍历DetailsView以隐藏动态BulletedList项

循环遍历DetailsView以隐藏动态BulletedList项
EN

Stack Overflow用户
提问于 2012-02-02 22:12:25
回答 1查看 826关注 0票数 0

我需要能够隐藏从动态项目列表(构建在DetailsView中)中显示的两个选项。每次我尝试通过BulletedList编写一个循环时,都会收到一个错误,说明它不是集合类型,所以我想我可以通过DetailsView循环找到我想要隐藏的项。

我不能更改SQL,因为这个特殊的项目符号列表在两个不同的页面上使用,只是在一个页面上,我只需要显示与ID相关的4个项中的2个。

代码语言:javascript
复制
<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>

我试过:

代码语言:javascript
复制
    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告诉我它不是集合类型。所以我想我可以在下面的代码中为每个人加上一个。我不知道如何循环通过DetailsView,谁能指出我在这里的正确方向吗?

代码语言:javascript
复制
Protected Sub dvSurveyQuestions_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dvSurveyQuestions.DataBound
End Sub

更新2/6:我使用一个BulletedList声明了我的FindControl,没有更多的错误说BulletedList没有声明。

代码语言:javascript
复制
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

另一个更新:我需要获得33的唯一blText的QuestionID。QuestionID是一个整数,但我不知道如何将HiddenField与Integer字段关联起来。在这段代码中," Is“得到下划线,表示Is operator does not accept opeands of type 'Integer.',因此我将Is改为an =并获取错误Operator = is not defined for types HiddenField and Integer.

代码语言:javascript
复制
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

,这就是工作原理

代码语言:javascript
复制
 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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-02 22:38:03

从BulletList的Items属性中循环。

代码语言:javascript
复制
    For Each i As ListItem In blText.Items

    Next

这可能更适合你的问题..。

代码语言:javascript
复制
    For intCursor = (blText.Items.Count - 1) To 0 Step -1

        If blText.Items(intCursor).Text = "TextValueToRemove" Then

            blText.Items.RemoveAt(intCursor)

        End If

    Next
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9120787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档