我是 vb.net 的新手。我有一些问题如何实现这个..我有gridview,按钮会根据列状态而改变..如果它的状态是“阻止”,按钮将是“解除阻止”,如果状态是空白,按钮将是“堵塞”。我的另一个问题是单击按钮后,选定的行按钮将在数据库中更新,如果用户单击“阻止”,则将状态更改为已阻止,然后该按钮将再次更改为“取消阻止”按钮,反之亦然。非常感谢您的帮助..
状态 | 解除封锁/封锁
(空白)| 块(按钮)
受阻| 阻止(应该是取消阻止按钮)
这段代码有什么问题..为什么它不起作用?
<asp:BoundField DataField="AllowStatus"
HeaderText="" ReadOnly="True"
SortExpression="AllowStatus">
<ItemStyle Width="300px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Block/Unblock">
<ItemTemplate>
<asp:Button ID="BlockButton" runat="server" CausesValidation="false" CommandName="" Text="Block" />
</ItemTemplate>
</asp:TemplateField>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) ' Handles GridView1.RowDataBound **<<ooops my mistake I comment out this >.< ..that's why it's not working**
If e.Row.RowType = DataControlRowType.DataRow Then
Dim allowstatus As String = (DataBinder.Eval(e.Row.DataItem, "AllowStatus")).ToString
Dim btn As Button = DirectCast(e.Row.FindControl("BlockButton"), Button)
If allowstatus = "Blocked" Then
btn.Text = "Unblocked"
End If
End If
End Sub