我需要在页面加载时根据特定条件禁用每行中的<asp:HyperLink>
。
到目前为止,我没有运气......
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()
方法永远不会改变。
任何帮助将不胜感激
答案 0 :(得分:1)
你似乎走在了正确的道路上,但是你却错过了每一行。我的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