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     }

 

posted @ 2012-05-14 18:00  旋转之刃  阅读(195)  评论(0编辑  收藏  举报