Repeater思路整理

目标 实现 小计=数量*单价

思路 javascript 控制

难点 Repeater 的生成控件Id 不一样

解决办法  后台获取 ClientID

前台代码

 <div class="tableList">
                        <table style="width: 1000px">
                            <tr style="background-color:#DFECFE">
                                <th class="style1">
                                    物品名称
                                </th>
                                <th width="80px">
                                    单位
                                </th>
                                <th width="80px">
                                    单价
                                </th>
                                <th width="80px">
                                    数量
                                </th>
                                <th width="50px">
                                    小计
                                </th>
                                <th width="50px">
                                    已付
                                </th>
                                <th width="70px">
                                    备注
                                </th>
                            </tr>
                            <asp:Repeater ID="repList" runat="server" OnItemDataBound="repList_ItemDataBound">
                                <ItemTemplate>
                                    <tr>
                                        <td>
                                            <asp:TextBox ID="GoodsName" runat='server' Width="90%" ></asp:TextBox><asp:Literal ID='btnSelect' runat='server' ></asp:Literal><asp:HiddenField
                                                ID="GoodsName_value" runat="server" />
                                        </td>
                                        <td>
                                            <asp:DropDownList ID="Unit_DictId" runat="server">
                                            </asp:DropDownList>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="Price" runat='server' Width="90%"></asp:TextBox>
                                        </td>
                                        <td>
                                          <asp:TextBox ID="StockNum" runat='server' Width="90%"></asp:TextBox>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="SubTotal" runat='server' Width="90%"></asp:TextBox>
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="Pay" runat="server" />
                                        </td>
                                        <td>
                                            <asp:TextBox ID="Mem" runat='server' Width="90%"></asp:TextBox>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </table>
                    </div>

 javascript代码

<script type='text/javascript'>
function GetSubToal(price, num, sub) {
    var price = document.getElementById(price.id).value;
    var num = document.getElementById(num.id).value;
    document.getElementById(sub.id).value = eval(price * num);
}
</script>

后台代码

 1     protected void repList_ItemDataBound(object sender, RepeaterItemEventArgs e)
 2     {
 3         if (e.Item.FindControl("GoodsName") != null)
 4         {
 5             TextBox txt = (TextBox)e.Item.FindControl("GoodsName");
 6             DropDownList list = (DropDownList)e.Item.FindControl("Unit_DictId");
 7             list.DataSource = dt_Dict;
 8             list.DataTextField ="数据名称";
 9             list.DataValueField = "Id";
10             list.DataBind();
11             Literal btnSelect = (Literal)e.Item.FindControl("btnSelect");
12             btnSelect.Text = "<a href='#' onClick=\"select('GoodsChoice.aspx','" + txt.ClientID + "','请选择物品');\">选择</a>";
13             TextBox Price_temp = (TextBox)e.Item.FindControl("Price");
14             TextBox StockNum_temp = (TextBox)e.Item.FindControl("StockNum");
15             TextBox SubTotal_temp = (TextBox)e.Item.FindControl("SubTotal");
16             SubTotal_temp.Attributes["OnFocus"] = "GetSubToal(" + Price_temp.ClientID + "," + StockNum_temp.ClientID + "," + SubTotal_temp.ClientID + ")";
17         }
18     }

 

转载于:https://www.cnblogs.com/P-lotor/archive/2012/05/14/2499731.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值