在 DataGrid 中找不到超链接控件
我需要根据页面加载时的特定条件在每一行中禁用
。 到目前为止,我没有任何运气...
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎走在正确的道路上,但您错过了查看每一行。我的 VB.net 很生锈,但我相信您想在循环中的几个位置添加 .Items(i) :
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: