在 DataGrid 中找不到超链接控件

发布于 2024-12-08 12:54:22 字数 1726 浏览 0 评论 0原文

我需要根据页面加载时的特定条件在每一行中禁用 。 到目前为止,我没有任何运气...

    For i As Integer = 0 To CourseData.Tables(0).Rows.Count - 1
        If CourseData.Tables(0).Rows(i)("completedyn") = "yes" Then
            CourseData.Tables(0).Rows(i)("completedyn") = "Complete"
        Else
            CourseData.Tables(0).Rows(i)("completedyn") = "Incomplete"
        End If
    Next

    grdCourses.DataSource = CourseData
    grdCourses.DataBind()

    For i As Integer = 0 To grdCourses.Items.Count - 1
        If grdCourses.FindControl("hypEnter") IsNot Nothing Then
            Dim hypEnter As HyperLink = CType(grdCourses.FindControl("hypEnter"), HyperLink)

            If CourseData.Tables(0).Rows(i)("completedyn") = "Incomplete" Then
                hypEnter.Enabled = False
            End If
        End If
    Next


    <asp:DataGrid runat="server" ID="grdCourses">
        <Columns>
            <asp:BoundColumn DataField="modulename" HeaderText="Module Name"></asp:BoundColumn>
            <asp:BoundColumn DataField="completedyn" HeaderText="Status"></asp:BoundColumn>
            <asp:BoundColumn DataField="completeddate" HeaderText="Date Completed"></asp:BoundColumn>
            <asp:TemplateColumn>
                <ItemTemplate>
                    <asp:HyperLink runat="server" ID="hypEnter" Text="View Module" NavigateUrl='<%# "View.aspx?mod=" + Eval("moduleid").ToString()%>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateColumn>
        </Columns>
    </asp:DataGrid>

FindControl() 方法永远不会改变。 任何帮助将不胜感激

I need to disable an <asp:HyperLink> in each of my rows based on a certain condition when the page loads.
So far, I'm not having any luck...

    For i As Integer = 0 To CourseData.Tables(0).Rows.Count - 1
        If CourseData.Tables(0).Rows(i)("completedyn") = "yes" Then
            CourseData.Tables(0).Rows(i)("completedyn") = "Complete"
        Else
            CourseData.Tables(0).Rows(i)("completedyn") = "Incomplete"
        End If
    Next

    grdCourses.DataSource = CourseData
    grdCourses.DataBind()

    For i As Integer = 0 To grdCourses.Items.Count - 1
        If grdCourses.FindControl("hypEnter") IsNot Nothing Then
            Dim hypEnter As HyperLink = CType(grdCourses.FindControl("hypEnter"), HyperLink)

            If CourseData.Tables(0).Rows(i)("completedyn") = "Incomplete" Then
                hypEnter.Enabled = False
            End If
        End If
    Next


    <asp:DataGrid runat="server" ID="grdCourses">
        <Columns>
            <asp:BoundColumn DataField="modulename" HeaderText="Module Name"></asp:BoundColumn>
            <asp:BoundColumn DataField="completedyn" HeaderText="Status"></asp:BoundColumn>
            <asp:BoundColumn DataField="completeddate" HeaderText="Date Completed"></asp:BoundColumn>
            <asp:TemplateColumn>
                <ItemTemplate>
                    <asp:HyperLink runat="server" ID="hypEnter" Text="View Module" NavigateUrl='<%# "View.aspx?mod=" + Eval("moduleid").ToString()%>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateColumn>
        </Columns>
    </asp:DataGrid>

The FindControl() method never changes.
Any help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城已无爱 2024-12-15 12:54:22

您似乎走在正确的道路上,但您错过了查看每一行。我的 VB.net 很生锈,但我相信您想在循环中的几个位置添加 .Items(i) :

For i As Integer = 0 To grdCourses.Items.Count - 1
    If grdCourses.Rows(i).FindControl("hypEnter") IsNot Nothing Then
        Dim hypEnter As HyperLink = CType(grdCourses.Rows(i).FindControl("hypEnter"), HyperLink)

        If CourseData.Tables(0).Rows(i)("completedyn") = "Incomplete" Then
            hypEnter.Enabled = False
        End If
    End If
Next

You appear to be on the right path, but you're missing looking in each row. My VB.net is rusty, but I believe you want to add .Items(i) in a few places in your loop:

For i As Integer = 0 To grdCourses.Items.Count - 1
    If grdCourses.Rows(i).FindControl("hypEnter") IsNot Nothing Then
        Dim hypEnter As HyperLink = CType(grdCourses.Rows(i).FindControl("hypEnter"), HyperLink)

        If CourseData.Tables(0).Rows(i)("completedyn") = "Incomplete" Then
            hypEnter.Enabled = False
        End If
    End If
Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文