为了账号安全,请及时绑定邮箱和手机立即绑定

ASP.NET简化编辑界面 V2

标签:
JavaScript


这篇与前一篇改进部分,也许大家会留意到动画演示,主要是GridVeiw的更新与删除会在每row都有。因此Insus.NET把它抽取出来,放在GridView外。致于一次性更新多笔记录,Insus.NET在很早之前已经录制过视频:http://www.cnblogs.com/insus/articles/1400150.html 。还有一个就是删除,在每row第一列放了一个CheckBox,让用户可以选择记录进行删除。

5acf07350001405b00110016.jpgView Code <asp:TemplateField>
                        <ItemStyle BorderWidth="1" BorderColor="#c0c0c0" Width="1%" />
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" onclick="Javascript:changeRowBgColor(this)" />
                        </ItemTemplate>
                    </asp:TemplateField>

 

删除前提示用户确认之后,再删除,但是在这里遇上一个问题,就是首先判断是否有选择记录,再confirm用户确认删除

还有一点要注意的地方,就是选择CheckBox之后,行可以Highlight,实现方可以参考:http://www.cnblogs.com/insus/archive/2011/09/07/2169742.html

 

以下较完整代码,仅供参考:

5acf07350001405b00110016.jpgView Code <asp:Table ID="Table1" runat="server" CssClass="table" CellPadding="2" CellSpacing="0">
                <asp:TableHeaderRow Height="20" BackColor="#efebde" BorderWidth="1" BorderColor="#c0c0c0">
                    <asp:TableHeaderCell BackColor="#efebde" BorderWidth="1" BorderColor="#c0c0c0">
                    Chinese Name
                    </asp:TableHeaderCell>
                    <asp:TableHeaderCell BackColor="#efebde" BorderWidth="1" BorderColor="#c0c0c0" Width="50%">
                    English Name
                    </asp:TableHeaderCell>
                </asp:TableHeaderRow>
                <asp:TableRow Height="20">
                    <asp:TableCell BorderWidth="1" BorderColor="#c0c0c0">
                        <asp:TextBox ID="txt_CName" runat="Server" CssClass="textbox" />
                    </asp:TableCell>
                    <asp:TableCell BorderWidth="1" BorderColor="#c0c0c0">
                        <asp:TextBox ID="txt_EName" runat="Server" CssClass="textbox" />
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
            <div style="margin-top: 3px; margin-bottom: 3px; padding: 3px;">
                <asp:Button ID="ButtonInsert" Text="Insert" runat="Server" OnClick="ButtonInsert_Click" />
                <asp:Button ID="ButtonUpdate" Text="Update" runat="Server" OnClick="ButtonUpdate_Click" />
                <asp:Button ID="ButtonDelete" Text="Delete" runat="Server" OnClick="ButtonDelete_Click"
                    CausesValidation="false" />
            </div>
            <asp:GridView ID="GvCutterType" runat="server" DataKeyNames="CutterTypeId" AutoGenerateColumns="false"
                CellPadding="2" CellSpacing="0" Width="100%" BorderWidth="0" BorderColor="#c0c0c0"
                RowStyle-Height="20" ShowHeader="false">
                <Columns>
                    <asp:TemplateField>
                        <ItemStyle BorderWidth="1" BorderColor="#c0c0c0" Width="1%" />
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" onclick="Javascript:changeRowBgColor(this)" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemStyle BorderWidth="1" BorderColor="#c0c0c0" />
                        <ItemTemplate>
                            <asp:TextBox ID="txtCName" runat="server" Text='<%# Eval("CName") %>'></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemStyle BorderWidth="1" BorderColor="#c0c0c0" Width="50%" />
                        <ItemTemplate>
                            <asp:TextBox ID="txtEName" runat="server" Text='<%# Eval("EName") %>'></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

 

xxx.aspx.cs:

5acf07350001405b00110016.jpgView Code   protected void ButtonInsert_Click(object sender, EventArgs e)
    {
       //do Insert something
        //obj.Insert(......);
    }
  
    protected void ButtonUpdate_Click(object sender, EventArgs e)
    {
        //reference this url: http://www.cnblogs.com/insus/articles/1400150.html
    }

    protected void ButtonDelete_Click(object sender, EventArgs e)
    {       
       //如何取得所有选择记录的主键:http://www.cnblogs.com/insus/articles/1413740.html       //http://www.cnblogs.com/insus/archive/2011/11/07/2238927.html
       // string dataKeyNames = xxx; 

       // string[] arr = dataKeyNames.Substring(1).Split(',');
        try
        {
            foreach (string s in arr)
            {
                //obj.Delter(s);
            }           
        }
        catch (Exception ex)
        {
            //alert exception message
        }
    } 

 

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消