详细信息视图不会进入编辑模式

发布于 2024-12-09 15:45:06 字数 6378 浏览 0 评论 0 原文

我似乎无法让详细信息视图进入编辑模式。我正在以编程方式绑定数据源。当项目命令为“编辑”时,我将模式更改为“编辑”并重新绑定数据源。我在控件数据绑定后检查,它仍然处于编辑模式,但详细信息视图未在编辑模式下显示。任何帮助将不胜感激。目前,我的详细信息视图已简化为一个元素以进行测试。 (这是来自 ASP.NET 论坛的交叉帖子,因为我很快就可以使用一些帮助)

ASPX:

<div style="width:990px;height:430px;">
    <div style="width:650px;height:430px;float:left;">
    <telerik:RadAjaxLoadingPanel ID="devicesLoadingPanel" runat="server" Skin="Simple" />
    <telerik:RadGrid ID="devicesRadGrid" runat="server" Skin="Simple" AllowPaging="true" Width="550" PageSize="15"
    AutoGenerateColumns="false"  DataSourceID="SqlDataSource1" OnSelectedIndexChanged="devicesGrid_SelectedIndexChanged">
        <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top">
            <Columns>
                <telerik:GridTemplateColumn HeaderText="Type" SortExpression="Type">
                    <ItemTemplate>
                        <asp:Label ID="lblType" runat="server" Text='<%# evalLabelType((Eval("UnitType"))) %>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn HeaderText="Name" DataField="Name" SortExpression="Name"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Description" DataField="Description" SortExpression="Description"></telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Location">
                    <ItemTemplate>
                        <asp:Label ID="lblDevicesLocation" runat="server" Text='<%# evalDevicesLocation(Eval("LocationID")) %>' />  
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        <CommandItemSettings ShowAddNewRecordButton="true" ShowRefreshButton="false"  />
        </MasterTableView>
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
    </telerik:RadGrid>

    </div>
    <div style="border: 1px solid #000;width:250px;height:430px;float:left;" >
        <asp:DetailsView ID="devicesDetailsView" runat="server" AutoGenerateRows="false" Width="200" Height="430" 
         CellPadding="0" GridLines="None" 
         OnItemCommand="devicesDetails_ItemCommand" OnDataBound="devicesDetails_DataBound">
            <Fields>
                <asp:TemplateField>
                    <ItemTemplate>
                        <span class="titles">Type:</span>
                        <asp:Label ID="lblType" runat="server" Text='<%# evalLabelType((Eval("UnitType"))) %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <span class="titles">Type:</span>
                        <asp:TextBox ID="txtType" runat="server" Text="test" />
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:CommandField ShowEditButton="true" ButtonType="Button" />
            </Fields>
        </asp:DetailsView>
    </div>

C#:

    protected void devicesGrid_SelectedIndexChanged(object sender, EventArgs e)
    {
        devicesDataKey = devicesRadGrid.SelectedItems[0].OwnerTableView.DataKeyValues[devicesRadGrid.SelectedItems[0].ItemIndex]["ID"].ToString();
        devicesDetailsView.DataSource = getDS(); 
        devicesDetailsView.DataBind();
    }

    protected void devicesDetails_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            // Switch mode and rebind
            devicesDetailsView.ChangeMode(DetailsViewMode.Edit);
            devicesDetailsView.DataSource = getDS();
            devicesDetailsView.DataBind(); 
        }
    }



    protected void devicesDetails_DataBound(object sender, EventArgs e)
    {

        //HideShowFields(devicesDataKey);  

        // Checking the mode again
        string test22 = devicesDetailsView.CurrentMode.ToString();
    }



    protected DataTable getDS()
    {

        string ID = devicesDataKey;

        // Get that device type!
        SqlCommand getDeviceType = new SqlCommand("SELECT UnitType FROM dbo.unit WHERE ID='" + ID + "'", connection);

        connection.Open();
        devicesTypeID = getDeviceType.ExecuteScalar().ToString();
        connection.Close();
        getDeviceType.Dispose(); 

        // This for attenuation. Depending on the device type it may pull from a different table.
        if (devicesTypeID == "2" || devicesTypeID == "3" || devicesTypeID == "4")
        {
            SqlCommand cmd = new SqlCommand("SELECT UnitType,Unit.Active,Name, Description, PrinterName, PrinterPort, PrinterIP, Unit.IPAddress, Unit.ID, LockHoldTimeout,LightOnTimeout, DoorAlertTimeout, EnableEmergAccess, EnableBizHours, ReaderAttenuation, Attenuation, Unit.LocationID, ScanTime FROM dbo.Unit INNER JOIN dbo.Readers on Unit.ID = Readers.UnitID WHERE Unit.ID='" + ID + "'", connection);
            DataTable dt = new DataTable();
            connection.Open();
            using (cmd)
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
            }
            connection.Close();
            // Attach the data to the details view
            return dt;
        }
        if (devicesTypeID == "5" || devicesTypeID == "6")
        {
            SqlCommand cmd = new SqlCommand("SELECT UnitType,Unit.Active,Name, Description, PrinterName, PrinterPort, PrinterIP, Unit.IPAddress, Unit.ID, LockHoldTimeout,LightOnTimeout, DoorAlertTimeout, EnableEmergAccess, EnableBizHours, ReaderAttenuation, Unit.LocationID, ScanTime, Attenuation FROM dbo.Unit, dbo.Readers WHERE Unit.ID='" + ID + "'", connection);
            DataTable dt = new DataTable();
            connection.Open();
            using (cmd)
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
            }
            connection.Close();
            // Attach the data to the details view
            return dt;
        }

        return null; 
    }

I can't seem to get my details view to enter edit mode. I am programatically binding the data source. When the item command is "edit" I change the mode to "edit" and rebind the datasource. I checked after the control databound and it's still in edit mode, but the details view is not displaying in edit mode. Any help would be greatly appreciated. Currently my details view is simplified to one element for testing. (this is a cross post from ASP.NET forums, since I could use some help relatively soon)

ASPX:

<div style="width:990px;height:430px;">
    <div style="width:650px;height:430px;float:left;">
    <telerik:RadAjaxLoadingPanel ID="devicesLoadingPanel" runat="server" Skin="Simple" />
    <telerik:RadGrid ID="devicesRadGrid" runat="server" Skin="Simple" AllowPaging="true" Width="550" PageSize="15"
    AutoGenerateColumns="false"  DataSourceID="SqlDataSource1" OnSelectedIndexChanged="devicesGrid_SelectedIndexChanged">
        <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top">
            <Columns>
                <telerik:GridTemplateColumn HeaderText="Type" SortExpression="Type">
                    <ItemTemplate>
                        <asp:Label ID="lblType" runat="server" Text='<%# evalLabelType((Eval("UnitType"))) %>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn HeaderText="Name" DataField="Name" SortExpression="Name"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderText="Description" DataField="Description" SortExpression="Description"></telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Location">
                    <ItemTemplate>
                        <asp:Label ID="lblDevicesLocation" runat="server" Text='<%# evalDevicesLocation(Eval("LocationID")) %>' />  
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        <CommandItemSettings ShowAddNewRecordButton="true" ShowRefreshButton="false"  />
        </MasterTableView>
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
    </telerik:RadGrid>

    </div>
    <div style="border: 1px solid #000;width:250px;height:430px;float:left;" >
        <asp:DetailsView ID="devicesDetailsView" runat="server" AutoGenerateRows="false" Width="200" Height="430" 
         CellPadding="0" GridLines="None" 
         OnItemCommand="devicesDetails_ItemCommand" OnDataBound="devicesDetails_DataBound">
            <Fields>
                <asp:TemplateField>
                    <ItemTemplate>
                        <span class="titles">Type:</span>
                        <asp:Label ID="lblType" runat="server" Text='<%# evalLabelType((Eval("UnitType"))) %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <span class="titles">Type:</span>
                        <asp:TextBox ID="txtType" runat="server" Text="test" />
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:CommandField ShowEditButton="true" ButtonType="Button" />
            </Fields>
        </asp:DetailsView>
    </div>

C#:

    protected void devicesGrid_SelectedIndexChanged(object sender, EventArgs e)
    {
        devicesDataKey = devicesRadGrid.SelectedItems[0].OwnerTableView.DataKeyValues[devicesRadGrid.SelectedItems[0].ItemIndex]["ID"].ToString();
        devicesDetailsView.DataSource = getDS(); 
        devicesDetailsView.DataBind();
    }

    protected void devicesDetails_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            // Switch mode and rebind
            devicesDetailsView.ChangeMode(DetailsViewMode.Edit);
            devicesDetailsView.DataSource = getDS();
            devicesDetailsView.DataBind(); 
        }
    }



    protected void devicesDetails_DataBound(object sender, EventArgs e)
    {

        //HideShowFields(devicesDataKey);  

        // Checking the mode again
        string test22 = devicesDetailsView.CurrentMode.ToString();
    }



    protected DataTable getDS()
    {

        string ID = devicesDataKey;

        // Get that device type!
        SqlCommand getDeviceType = new SqlCommand("SELECT UnitType FROM dbo.unit WHERE ID='" + ID + "'", connection);

        connection.Open();
        devicesTypeID = getDeviceType.ExecuteScalar().ToString();
        connection.Close();
        getDeviceType.Dispose(); 

        // This for attenuation. Depending on the device type it may pull from a different table.
        if (devicesTypeID == "2" || devicesTypeID == "3" || devicesTypeID == "4")
        {
            SqlCommand cmd = new SqlCommand("SELECT UnitType,Unit.Active,Name, Description, PrinterName, PrinterPort, PrinterIP, Unit.IPAddress, Unit.ID, LockHoldTimeout,LightOnTimeout, DoorAlertTimeout, EnableEmergAccess, EnableBizHours, ReaderAttenuation, Attenuation, Unit.LocationID, ScanTime FROM dbo.Unit INNER JOIN dbo.Readers on Unit.ID = Readers.UnitID WHERE Unit.ID='" + ID + "'", connection);
            DataTable dt = new DataTable();
            connection.Open();
            using (cmd)
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
            }
            connection.Close();
            // Attach the data to the details view
            return dt;
        }
        if (devicesTypeID == "5" || devicesTypeID == "6")
        {
            SqlCommand cmd = new SqlCommand("SELECT UnitType,Unit.Active,Name, Description, PrinterName, PrinterPort, PrinterIP, Unit.IPAddress, Unit.ID, LockHoldTimeout,LightOnTimeout, DoorAlertTimeout, EnableEmergAccess, EnableBizHours, ReaderAttenuation, Unit.LocationID, ScanTime, Attenuation FROM dbo.Unit, dbo.Readers WHERE Unit.ID='" + ID + "'", connection);
            DataTable dt = new DataTable();
            connection.Open();
            using (cmd)
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
            }
            connection.Close();
            // Attach the data to the details view
            return dt;
        }

        return null; 
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

要走就滚别墨迹 2024-12-16 15:45:07

我发现了,事实证明我的 Telerik Ajax 经理隐藏了我遇到的错误。我收到“DetailsView 触发事件 ModeChanging”,我使用以下链接中的说明解决了该问题: forums.asp.net

I figured it out, it turns out my Telerik Ajax Manager was hiding the error I was getting. I was getting "The DetailsView fired event ModeChanging", which I resolved using the instructions in the following link: forums.asp.net

韬韬不绝 2024-12-16 15:45:07

@Will 提到的 asp.net 论坛链接的简单摘要:

protected void dvSupplier_ModeChanging(object sender, DetailsViewModeEventArgs e)
    {
        dvSupplier.ChangeMode(e.NewMode);
        this.SetData();
    }

A simple summary from the asp.net forum link that @Will mentions:

protected void dvSupplier_ModeChanging(object sender, DetailsViewModeEventArgs e)
    {
        dvSupplier.ChangeMode(e.NewMode);
        this.SetData();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文