【问题标题】:insert new and insert close插入新的并插入关闭
【发布时间】:2013-07-05 11:27:57
【问题描述】:

我遇到了问题, 所以我有一个包含“插入和新建”和“插入和关闭”按钮的表单。 插入和新建按钮可让您插入一行并重新打开表单以插入另一行。 但是插入和关闭按钮在添加一行后关闭。 无论如何,我的问题如下: 我正在使用命令字段从我的数据库中插入、更新或删除。

插入和关闭按钮正在工作 但插入和新建按钮不是因为我无法在我的表中添加一行。 我只是想看看我是否可以在我的命令字段中添加一个“插入和新建”按钮,以便我可以使用它(知道我已经使用了所有按钮(删除、插入、更新..)。

谢谢。

【问题讨论】:

  • 显示一些代码,即使它已损坏

标签: c# telerik telerik-grid commandfield


【解决方案1】:

请尝试以下代码 sn-p。

ASPX

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView CommandItemDisplay="Top" EditMode="InPlace">
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn>
                <InsertItemTemplate>
                    <asp:Button ID="Button1" runat="server" Text="insert and new" CommandName="insertandnew" />
                    <asp:Button ID="Button2" runat="server" Text="insert and close" CommandName="insertandclose" />
                </InsertItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

ASPX.CS

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
        new { ID = 1, Name ="Name1"},
        new { ID = 2, Name = "Name2"},
        new { ID = 3, Name = "Name3"},
         new { ID = 4, Name = "Name4"},
        new { ID = 5, Name = "Name5"}
    };

    RadGrid1.DataSource = data;

}

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "insertandnew")
    {
        // Perform Your Insert operation
        e.Canceled = true;

        //Set insertmonde once again
        RadGrid1.MasterTableView.IsItemInserted = true;
        RadGrid1.Rebind();
    }
    else if (e.CommandName == "insertandclose")
    {
        // Perform Your Insert operation
        RadGrid1.MasterTableView.IsItemInserted = false;
        RadGrid1.Rebind();
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 2015-05-30
    相关资源
    最近更新 更多