Jquery片段:

<script type="text/javascript">
        function compute(nbBoxQuantity, lblQuantityPerBox, lblQuantity, nbPrice, lblTotalAmounts) {
            if (nbBoxQuantity.value == "" || nbBoxQuantity.length == 0) {
                nbBoxQuantity.value = 0;
            }
            if (lblQuantityPerBox.innerText == "" || lblQuantityPerBox.length == 0) {
                lblQuantityPerBox.innerText(0);
            }
            if (nbPrice.value == "" || nbPrice.length == 0) {
                nbPrice.value = 0;
            }
            if (lblQuantity.innerText == "" || lblQuantity.length == 0) {
                lblQuantity.innerText(0);
            }
            lblQuantity.innerText = nbBoxQuantity.value * lblQuantityPerBox.innerText;
            lblTotalAmounts.innerText = nbPrice.value * lblQuantity.innerText;
        }
    </script>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

前台片段:

<swc:DataGridView ID="dgvList" runat="server" DataKeyNames="ID"
                        AllowSorting="true" CurrentSortField="GoodsId"
                        OnRowDeleting="dgvList_RowDeleting" OnRowEditing="dgvList_RowEditing" OnRowDataBound="dgvList_RowDataBound" OnRowCommand="dgvList_RowCommand"
                        OnRowCancelingEdit="dgvList_RowCancelingEdit" OnRowUpdating="dgvList_RowUpdating">
                        <Columns>
                            <swc:TemplateField HeaderText="Id" Visible="false">
                                <ItemTemplate>
                                    <asp:Literal runat="server" ID="ltlId"></asp:Literal>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Literal runat="server" ID="ltlId"></asp:Literal>
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="编号" Width="100" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Literal runat="server" ID="ltlGoodsCode"></asp:Literal>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Literal runat="server" ID="ltlGoodsCode"></asp:Literal>
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="名称" Width="100" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Literal runat="server" ID="ltlGoodsName"></asp:Literal>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Literal runat="server" ID="ltlGoodsName"></asp:Literal>
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="类型" Width="60" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlType" runat="server" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Literal ID="ltlType" runat="server" />
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="赠品" Width="60" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlIsGift" runat="server" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:DropDownList ID="ddlIsGift" runat="server">
                                        <asp:ListItem Value="True">是</asp:ListItem>
                                        <asp:ListItem Value="False">否</asp:ListItem>
                                    </asp:DropDownList>
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="箱数" Width="60" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlBoxQuantity" runat="server" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <swc:NumberBox ID="nbBoxQuantity" runat="server" Digit="0" Width="60" />
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="每箱数" Width="60" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Label ID="lblQuantityPerBox" runat="server"></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Label ID="lblQuantityPerBox" runat="server"></asp:Label>
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="数量" Width="60" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Label ID="lblQuantity" runat="server"></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Label ID="lblQuantity" runat="server"></asp:Label>
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="单价" Width="60" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlPrice" runat="server" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <swc:NumberBox ID="nbPrice" runat="server" Digit="2" Width="60" />
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <swc:TemplateField HeaderText="总价" Width="60" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Label ID="lblTotalAmounts" runat="server"></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Label ID="lblTotalAmounts" runat="server"></asp:Label>
                                </EditItemTemplate>
                            </swc:TemplateField>
                            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" HeaderText="操作" HeaderStyle-Width="60" />
                        </Columns>
                    </swc:DataGridView>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

后台片段:

protected void dgvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow row = e.Row;
            switch (row.RowType)
            {
                case DataControlRowType.DataRow:
                    SC_PurchaseItem item = row.DataItem as SC_PurchaseItem;
                    if (item.Id != Guid.Empty)
                    {
                        Literal ltlId = row.FindControl<Literal>("ltlId");
                        Literal ltlGoodsCode = row.FindControl<Literal>("ltlGoodsCode");
                        Literal ltlGoodsName = row.FindControl<Literal>("ltlGoodsName");
                        Literal ltlType = row.FindControl<Literal>("ltlType");
                        Label lblQuantityPerBox = row.FindControl<Label>("lblQuantityPerBox");
                        Label lblQuantity = row.FindControl<Label>("lblQuantity");
                        Label lblTotalAmounts = row.FindControl<Label>("lblTotalAmounts");
 
                        var good = bll.Get<M_Goods>(item.GoodsId);
                        ltlId.Text = item.Id.ToString();
                        ltlGoodsCode.Text = good.GoodsCode;
                        ltlGoodsName.Text = good.GoodsName;
                        ltlType.Text = good.GoodsType.ToText();
                        lblQuantityPerBox.Text = item.QuantityPerBox.ToString();
 
                        //if (e.Row.RowState == DataControlRowState.Edit)
                        if (e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Edit) || e.Row.RowState == DataControlRowState.Edit)
                        {
                            System.Web.UI.WebControls.DropDownList ddlIsGift = row.FindControl<System.Web.UI.WebControls.DropDownList>("ddlIsGift");
                            NumberBox nbBoxQuantity = row.FindControl<NumberBox>("nbBoxQuantity");
                            NumberBox nbPrice = row.FindControl<NumberBox>("nbPrice");
 
                            ddlIsGift.SelectedValue = item.IsGift.ToString();
                            nbBoxQuantity.Value = item.BoxQuantity.ToHtmlDecode();
                            nbPrice.Text = item.Price.ToHtmlDecode();
 
                            nbBoxQuantity.Attributes.Add("onchange", "compute(" + nbBoxQuantity.ClientID + "," + lblQuantityPerBox.ClientID + "," + lblQuantity.ClientID + "," + nbPrice.ClientID + "," + lblTotalAmounts.ClientID + ");");
                            nbPrice.Attributes.Add("onchange", "compute(" + nbBoxQuantity.ClientID + "," + lblQuantityPerBox.ClientID + "," + lblQuantity.ClientID + "," + nbPrice.ClientID + "," + lblTotalAmounts.ClientID + ");");
                        }
                        else
                        {
                            Literal ltlIsGift = row.FindControl<Literal>("ltlIsGift");
                            Literal ltlBoxQuantity = row.FindControl<Literal>("ltlBoxQuantity");
                            Literal ltlPrice = row.FindControl<Literal>("ltlPrice");
 
                            ltlIsGift.Text = item.IsGift ? "是" : "否";
                            ltlBoxQuantity.Text = item.BoxQuantity.ToHtmlDecode();
                            ltlPrice.Text = item.Price.ToHtmlDecode();
                        }
                        lblQuantity.Text = (item.BoxQuantity * item.QuantityPerBox).ToHtmlDecode();
                        lblTotalAmounts.Text = ((item.BoxQuantity * item.QuantityPerBox) * item.Price).ToHtmlDecode();
                    }
                    break;
            }
        }
        protected void dgvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
 
        }
 
        protected void dgvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridView gv = (GridView)sender;
            string id = ((System.Web.UI.WebControls.Literal)gv.Rows[e.RowIndex].FindControl("ltlId")).Text;
            SC_PurchaseItem entity = new SC_PurchaseItem
            {
                Id = new Guid(id),
                UpdatedDate = DateTime.Now,
                UpdatedUser = CurrentUser.DisplayName
            };
            PurchaseBll bll = new PurchaseBll();
            bll.DeletePurchaseItem(entity);
            this.BindGrid();
        }
        protected void dgvList_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView gv = (GridView)sender;
            gv.EditIndex = e.NewEditIndex;
            this.BindGrid();
        }
        protected void dgvList_Sorting(object sender, GridViewSortEventArgs e)
        {
            this.BindGrid();
        }
        protected void dgvList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            dgvList.EditIndex = -1;
            this.BindGrid();
        }
        protected void dgvList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridView gv = (GridView)sender;
            string id = ((System.Web.UI.WebControls.Literal)gv.Rows[e.RowIndex].FindControl("ltlId")).Text;
            bool ddlIsGift = ((System.Web.UI.WebControls.DropDownList)gv.Rows[e.RowIndex].FindControl("ddlIsGift")).SelectedValue.As<bool>();
            int nbBoxQuantity = ((NumberBox)gv.Rows[e.RowIndex].FindControl("nbBoxQuantity")).Value.As<int>();
            int lblQuantity = ((Label)gv.Rows[e.RowIndex].FindControl("lblQuantity")).Text.As<int>();
            decimal nbPrice = ((NumberBox)gv.Rows[e.RowIndex].FindControl("nbPrice")).Value.As<decimal>();
 
            PurchaseBll bll = new PurchaseBll();
            SC_PurchaseItem entity = new SC_PurchaseItem
            {
                Id = new Guid(id),
                IsGift = ddlIsGift,
                BoxQuantity = nbBoxQuantity,
                Quantity = lblQuantity,
                Price = nbPrice,
                UpdatedDate = DateTime.Now,
                UpdatedUser = CurrentUser.DisplayName
            };
            bll.UpdatePurchaseItem(entity);
 
            gv.EditIndex = -1;
            this.BindGrid();
        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Gridview编辑时Jquery自动计算自定义列(鼠标离开输入框Jquery计算)的更多相关文章

  1. jquery.datetimepicker.js 当鼠标离开时,不选中当前时间,以达到清空的目的

    validateOnBlur:true    当鼠标离开时,不选中当前时间,以达到清空的目的 使用方法:   // 时间设置         $('#BankProduct_sale_begin'). ...

  2. Asp.Net:GridView 编辑、删除、自定义分页以后备用

    页面 GridView 绑定:在中,有 <asp:BoundField/>和 <asp:TemplateField><ItemTemplate>嵌套服务器控件 &l ...

  3. 在Gridview编辑时添加DropDownList控件并设置默认值

    页面代码: <asp:GridView ID="GridView1" runat="server"             AutoGenerateCol ...

  4. jquery自定义滚动条 鼠标移入或滚轮时显示 鼠标离开或悬停超时时隐藏

    一.需求: 我需要做一个多媒体播放页面,左侧为播放列表,右侧为播放器.为了避免系统滚动条把列表和播放器隔断开,左侧列表的滚动条需要自定义,并且滚动停止和鼠标离开时要隐藏掉. 二.他山之石: 案例来自h ...

  5. 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结

    史上最全的CSS hack方式一览 2013年09月28日 15:57:08 阅读数:175473 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...

  6. 利用自定义动画 animate() 方法,实现某图书网站中“近 7 日畅销榜”中的图书无缝垂直向上滚动特效:当光标移入到图书上时,停止滚动,鼠标移开时,继续滚动

    查看本章节 查看作业目录 需求说明: 利用自定义动画 animate() 方法,实现某图书网站中"近 7 日畅销榜"中的图书无缝垂直向上滚动特效:当光标移入到图书上时,停止滚动,鼠 ...

  7. EasyUI Datagrid 自定义列、Foolter及单元格编辑

    1:自定义列,包括 Group var head1Array = []; head1Array.push({ field: 'Id', title: 'xxxx', rowspan: 2 }); he ...

  8. GridView数据绑定控件的模版列时设置显示的格式

    形式 语法 结果 数字 {0:N2} 12.36   数字 {0:N0} 13   货币 {0:c2} $12.36   货币 {0:c4} $12.3656   货币 "¥{0:N2}&q ...

  9. 在【自定义列】中编辑简单运算公式(Power Query 之 M 语言)

    数据源: "品名"."数量"."单价"三列 目标: 计算销售单价(单价*1.2) 解决方案: 在[自定义列]中使用乘法四则运算 步骤: 打开 ...

随机推荐

  1. warning: control reaches end of non-void function

    用gcc编译一个程序的时候出现这样的警告: warning: control reaches end of non-void function 它的意思是:控制到达非void函数的结尾.就是说你的一些 ...

  2. 【转】IOS开发小技巧

    1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view [ ...

  3. Orchard 源码探索(Log)

    简单工厂模式.抽象工厂模式和适配器模式 依赖倒置原则也叫依赖倒转原则,Dependence Inversion Principle,对抽象进行编程,不要对实现进行编程. A.高层次的模块不应该依赖于低 ...

  4. 优盘(U 盘) 采用TLC, MLC, SLC芯片 的区别 与使用寿命

    最近一直在看大家在讨论sandisk,pny,金士顿等大厂都开始用tlc的芯片问题,让大家基本都不敢用U盘存数据了按照之前的擦写参数TLC        1000次MLC       10000次SL ...

  5. 用sqlserver处理excel表格

    本来最近在研究微信公众平台的,老大临时交我个任务,把excel表格里的数据导入sql数据库,我想这so easy嘛. 没想都在上面消磨了两天... 把情况介绍下:在数据库中有如下这样结构的表(A表) ...

  6. [Oracle] Listener的动态注册

    在有Oracle Listener的动态注册之前,采用的是静态注册,所谓静态注册是指Oracle实例在启动时,读取listener.ora里的配置,然后注册到Listener,它主要有两个缺点: 1. ...

  7. Java反射-简单应用

    为了程序更好的维护和扩展,在面向对象思维的世界里,首先是面向接口编程,然后我们应该把做什么和怎么做进行分离. 以下我将用一个开晚会的样例来演示一下,终于达到的效果是:工厂+反射+配置文件实现程序的灵活 ...

  8. 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)

    前言 本章将实现非常实用的功能——下载在线视频.涉及到多线程.线程更新UI等技术,还需思考产品的设计,如何将新加的功能更好的融入到现有的产品中,并不是简单的加一个界面就行了,欢迎大家交流产品设计和技术 ...

  9. HTML5的绘图的支持

    一.简单介绍canvas元素 <canvas.../>是HTML5新增的一个元素,该元素用于绘制图形.实际上<canvas../>只是相当于一张画布. 它除了可以指定通用属性外 ...

  10. 用for循环遍历DataTable中的数据

    for (int i = 0; i < dataTable.Rows.Count; i++) { for (int j = 0; j < dataTable.Columns.Count;  ...