惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
V
Visual Studio Blog
有赞技术团队
有赞技术团队
U
Unit 42
D
Docker
小众软件
小众软件
F
Full Disclosure
I
Intezer
Scott Helme
Scott Helme
P
Privacy International News Feed
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
B
Blog
Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
宝玉的分享
宝玉的分享
S
Security Affairs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
Schneier on Security
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Threat Research - Cisco Blogs
量子位
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Heimdal Security Blog
N
Netflix TechBlog - Medium
H
Hacker News: Front Page
P
Proofpoint News Feed
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
S
Schneier on Security

博客园 - 五蕴非空

AI工具实践日记(二):在 OpenClaw 中调用 OpenCode 进行开发任务 AI工具实践日记(一):在树莓派上搭建OpenClaw,一个后端开发者的真实踩坑记录 .net core XML 解析帮助类 常用工具类 .net Core 同一接口不同实现的依赖注入 - 五蕴非空 大批量数据操作的性能优化方案 .net core 3.1 配置文件立即更新 为.net Core 3.0 WebApi 创建Linux守护进程 asp.net core 3.0 JObject The collection type 'Newtonsoft.Json.Linq.JObject' is not supported .net Core2.2 WebApi通过OAuth2.0实现微信登录 Asp.net导出Excel文件 Ext.Net 使用总结之GridPanel中的选中行 Ext.Net 使用总结之查询条件中的起始日期 使用 NuGet 管理项目库 JavaScript 获取客户端计算机硬件及系统信息 程序员技术练级攻略 ThoughtWorks(中国)程序员读书雷达 Sql 分割 键值对字符串 得到某值对应的名称 Ext.net 中日期格式的计算
Ext.Net 使用总结之GridPanel的删除事件
五蕴非空 · 2013-08-14 · via 博客园 - 五蕴非空

1.关于Ext.net中GridPanel的删除事件

首先是GridPanel,如下:

 <ext:GridPanel ID="GridPanel1" runat="server" AutoScroll="true" Layout="FitLayout" AutoExpandColumn="REMARK">
      <ColumnModel ID="ColumnModel1" runat="server">
           <Columns>
                <ext:RowNumbererColumn Header="序号" Width="35" />
                <ext:Column Header="ID" DataIndex="ID" Hidden="true"/>
                <ext:Column Header="名称" DataIndex="NAME" Width="150"/>
                <ext:Column Header="类别" DataIndex="TYPE" Width="120"/>
                <ext:Column Header="备注" DataIndex="REMARK"/>
           </Columns>
       </ColumnModel>
       <Store>
           <ext:Store ID="Store1" runat="server" AutoLoad="true" OnRefreshData="OnData_Refresh">
                <Proxy>
                     <ext:PageProxy>
                     </ext:PageProxy>
                </Proxy>
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                         <Fields>
                              <ext:RecordField Name="ID" />
                              <ext:RecordField Name="NAME" />
                              <ext:RecordField Name="TYPE" />
                              <ext:RecordField Name="REMARK" />
                         </Fields>
                    </ext:JsonReader>
                 </Reader>
            </ext:Store>
        </Store>
        <SelectionModel>
            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server">
            </ext:RowSelectionModel>
        </SelectionModel>
        <BottomBar>
            <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="20" StoreID="Store1" Height="25" DisplayInfo="true" DisplayMsg="显示{0} - {1},共{2}条" EmptyMsg="没有可显示的记录" />
        </BottomBar>
  </ext:GridPanel>

我们再增加一个删除按钮,如下:

<ext:Button ID="extBtn_Delete" runat="server" Text="删除" Icon="Delete">
    <DirectEvents>
        <Click OnEvent="extBtn_Delete_Click" />
    </DirectEvents>
</ext:Button>

删除按钮的后台事件,如下:

    protected void extBtn_Delete_Click(object sender, DirectEventArgs e)
    {
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        if (sm.SelectedRows.Count == 0)
        {
            X.Msg.Alert("系统提示", "请先选择要删除的记录!").Show();
            return;
        }
        X.Msg.Confirm("系统提示", "是否删除选中行?", new MessageBoxButtonsConfig
        {
            Yes = new MessageBoxButtonConfig
            {
                Handler = "Ext.net.DirectMethods.DoDel();",
                Text = "是"
            },
            No = new MessageBoxButtonConfig
            {
                Text = "否"
            }
        }).Show();
    }

    [DirectMethod]
    public void DoDel()
    {
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        try
        {
            foreach (SelectedRow row in sm.SelectedRows)
            {
                //这里是删除数据的方法,可以用 row.RecordID 属性拿到选中行的主键ID
                GridPanel1.DeleteSelected();
                Store1.CommitChanges();
            }
        }
        catch(Exception ex)
        {
            X.Msg.Alert("系统提示", "删除记录失败!|"+ex.Message).Show();
            return;
        }
        GridPanel1.Reload();
    }

这一段是整个删除的重点,其中提到的主键ID是指在Store中设置的IDProperty属性。

GridPanel1.DeleteSelected();
Store1.CommitChanges();

这两行是用来清空GridPanel中的选中行,不清空的话会对之后的选中事件造成影响。

请注意:本文用到的Ext.net版本是1.x