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

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
Scott Helme
Scott Helme
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
J
Java Code Geeks
U
Unit 42
The GitHub Blog
The GitHub Blog
H
Help Net Security
T
Tenable Blog
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
L
Lohrmann on Cybersecurity
T
Threatpost
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
L
LINUX DO - 最新话题
K
Kaspersky official blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threat Research - Cisco Blogs
C
Check Point Blog
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
Y
Y Combinator Blog
N
News | PayPal Newsroom
M
MIT News - Artificial intelligence
Latest news
Latest news
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
I
Intezer
爱范儿
爱范儿
F
Fortinet All Blogs
P
Palo Alto Networks Blog
C
CERT Recently Published Vulnerability Notes

博客园 - 五蕴非空

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