在插入模式下绑定详细信息视图

本文关键字:详细信息 视图 绑定 插入 模式 | 更新日期: 2023-09-27 18:26:33

我一直在到处寻找解决这个问题的方法,现在是时候问了。

以下是详细视图:

<asp:DetailsView ID="dvConnPipe" runat="server" AutoGenerateRows="False" ForeColor="#333333"
    GridLines="None" Width="100%">
    <Fields>
        <asp:TemplateField HeaderText="Connection Pipe 1" SortExpression="ConnectionPipe1">
            <EditItemTemplate>
                <asp:TextBox ID="txtConnectionPipe1" runat="server" Text='<%# Bind("ConnectionPipe1") %>'
                    onkeydown="return FloatOnly(event)"></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtConnectionPipe1" runat="server" Text='<%# Bind("ConnectionPipe1") %>' onkeydown="return FloatOnly(event)"></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("ConnectionPipe1") %>'></asp:Label>
            </ItemTemplate>
            <ControlStyle Width="50px" />
        </asp:TemplateField>                                    
    </Fields>  
</asp:DetailsView>

下拉列表中选择的索引发生了变化:

protected void ddlFormItem_SelectedIndexChanged(object sender, EventArgs e)
{            
    DropDownList ddlFormItem = (DropDownList)sender;           
    if (ddlFormItem.SelectedValue != "-1")
    {
        int CopyID = int.Parse(ddlFormItem.SelectedValue);
        //SetInsertMode(); //If insert mode, does not bind
        //SetReadOnlyMode(); //If read only, it binds OK
        BindViews(CopyID);
    }            
}
private void BindViews(int CopyID)
{
    DataTable dt = BLL.SOCBll.GetConditions(CopyID); 
    dvConnPipe.DataSource = dt;
    dvConnPipe.DataBind();
    //More views below
}

必须能够在插入模式下绑定详细信息视图。

如果我改为只读,它绑定正常。

我不想找到每个控件并将其设置为那样。

在插入模式下绑定详细信息视图

经过大量搜索,我确实发现在插入模式下无法绑定细节视图。对于所有视图,我必须找到每个控件并设置默认值。