根据数据表值为特定行Gridview启用Linkbutton [英] Enable Linkbutton for a specific row Gridview based on datatable value
本文介绍了根据数据表值为特定行Gridview启用Linkbutton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个绑定到Gridview的数据表。现在在数据表中,如果列[文件]具有文件名,则在Gridview中为该相应行启用链接按钮,如果列[文件]没有文件名,则禁用Gridview中该行的链接按钮。
这是我试过的东西
I have a Datatable that is binding to Gridview. Now in that Datatable if a column["File"] has File name then Enable linkbutton for that respective row in Gridview, if column["File"] doesn't have Filename then disable Linkbutton of that row in Gridview.
Here is what I tried
Protected Sub gdvLineItems_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Dim rowIndex As Integer = 0
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim dt As DataTable = ViewState("Grid")
For i As Integer = 1 To dt.Rows.Count
Dim lnk As LinkButton = DirectCast(e.Row.FindControl("btndownload"), LinkButton)
If Not dt.Rows(rowIndex)("File") Is String.Empty Then
lnk.Enabled = True
Else
lnk.Enabled = False
End If
rowIndex += 1
Next
End If
End Sub
注意:每次有人输入数据时,我的数据表都会更新,每行都附加到Gridview。
Note: My Datatable gets updated each time someone enters data, and each row is appended to Gridview.
推荐答案
在Linkbutton转换行上放置断点并查看。字符串的常见问题是可能发生的多种事情。您正在测试空字符串/零长度字符串。可以为null,可以是空格等。使用带断点的locals窗口或只在代码中将属性赋值给字符串。必须确定你拥有的东西。
Put breakpoint on Linkbutton cast row and have a look. Also common problem with strings is the multiple things that can happen. You are testing for empty string/zero length string. Could be null, could be space, etc. Use locals window with breakpoint or just assign property to string in code. Must be sure what you have.
这篇关于根据数据表值为特定行Gridview启用Linkbutton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文