asp.net - 仅当 FormView 为空时才以插入模式打开 FormView

标签 asp.net vb.net formview

我有一个 FormView,只有当表单不包含数据时,我才想在插入模式下打开它。我尝试过以下 if 语句:

If True Then
If SomeFormView.DataItemCount = 0 Then
    SomeFormView.ChangeMode(FormViewMode.Insert)
Else
    SomeFormView.ChangeMode(FormViewMode.Edit)
End If


 End If

但它在插入中打开是否为空?

最佳答案

在执行该检查之前,您需要等到 FormView 已进行数据绑定(bind),否则您将始终得到“true”(因为它确实有零个项目,直到您将其绑定(bind)到任何数据源)向其提供上述元素)。您可以在 databound 中执行此操作事件,最好是:

SomeFormView_Databound (ByVal sender As Object, ByVal e As EventArgs) Handles SomeFormView.DataBound
{
    If SomeFormView.DataItemCount = 0 Then
        SomeFormView.ChangeMode(FormViewMode.Insert)
    Else
        SomeFormView.ChangeMode(FormViewMode.Edit)
    End If
}

关于asp.net - 仅当 FormView 为空时才以插入模式打开 FormView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9978929/

相关文章:

javascript - asp.net json 显示奇怪的结果

c# - 如何从 GridView 更新事件中的 GridView 编辑事件中获取保存在字符串中的值?

c# - 如何快速将 object[,] 向上转换为 double[,]?

c# - VB WPF 到 C# WPF

c# - 窗体 View 被清除

.net - 将 CSS 应用于 formview 控件中的文本框

asp.net - VB.Net 路径中的反斜杠

c# - 为什么 .net 在分配给日期字段时将此日期解释为前一天?

c# - 在另一个窗体 View 中单击按钮时窗体 View 数据源丢失

c# - 如何在 ASP.NET 中将 DataFormatString 设置为 Textbox?