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

推荐订阅源

W
WeLiveSecurity
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
Cloudbric
Cloudbric
The Register - Security
The Register - Security
小众软件
小众软件
PCI Perspectives
PCI Perspectives
G
Google Developers Blog
AI
AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
TaoSecurity Blog
TaoSecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
F
Full Disclosure
N
Netflix TechBlog - Medium
博客园_首页
Last Week in AI
Last Week in AI
A
Arctic Wolf
B
Blog RSS Feed
J
Java Code Geeks
C
Cybersecurity and Infrastructure Security Agency CISA
I
InfoQ
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
NISL@THU
NISL@THU
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
有赞技术团队
有赞技术团队
S
Schneier on Security
L
Lohrmann on Cybersecurity
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Security Latest
Security Latest
Vercel News
Vercel News
博客园 - 司徒正美
Webroot Blog
Webroot Blog
Hacker News: Ask HN
Hacker News: Ask HN
A
About on SuperTechFans

博客园 - 五蕴非空

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