Visual Basic隐藏DataBound上的行

时间:2014-06-05 19:51:00

标签: vb.net

我正在尝试将行设置为不可见的用户选择True但方法不起作用。请帮忙。

谢谢!

 Protected Sub dg_RowDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound

        Dim ddl As New DropDownList
        Dim lbl As New Label
        Dim ddlretired As New DropDownList
        Dim lblretired As New Label
        If (e.Item.ItemType = ListItemType.EditItem And dg.EditItemIndex = e.Item.ItemIndex) Then

            ddl = e.Item.FindControl("ddlType")
            lbl = e.Item.FindControl("lbltype")

            ddlretired = e.Item.FindControl("ddlEdit")
            lblretired = e.Item.FindControl("lblretired")

            ddl.Items.FindByText(lbl.Text).Selected = True
            ddlretired.Items.FindByText(lblretired.Text).Selected = True

            lbl.Visible = False
            lblretired.Visible = False

        End If

 End Sub

1 个答案:

答案 0 :(得分:0)

我相信在将可见性设置为false之前,您必须暂停绑定。

从下面的链接

CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource];  
currencyManager1.SuspendBinding();
MyGrid.Rows[5].Visible = false;
currencyManager1.ResumeBinding();

Unable To set row visible false of a datagridview