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

推荐订阅源

L
LINUX DO - 最新话题
G
Google Developers Blog
J
Java Code Geeks
The GitHub Blog
The GitHub Blog
F
Full Disclosure
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
Help Net Security
Help Net Security
The Hacker News
The Hacker News
IT之家
IT之家
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
V
Visual Studio Blog
博客园 - 聂微东
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
Know Your Adversary
Know Your Adversary
Security Latest
Security Latest
Security Archives - TechRepublic
Security Archives - TechRepublic
Simon Willison's Weblog
Simon Willison's Weblog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Last Week in AI
Last Week in AI
Schneier on Security
Schneier on Security
N
News and Events Feed by Topic
博客园 - 【当耐特】
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
Google DeepMind News
Google DeepMind News
Cloudbric
Cloudbric
N
News | PayPal Newsroom
A
About on SuperTechFans
S
Schneier on Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
雷峰网
雷峰网
T
The Exploit Database - CXSecurity.com
罗磊的独立博客
K
Kaspersky official blog
The Cloudflare Blog
I
Intezer

博客园 - 五蕴非空

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