Repeater思路整理
目標(biāo) 實(shí)現(xiàn) 小計(jì)=數(shù)量*單價(jià)
思路 javascript 控制
難點(diǎn) Repeater 的生成控件Id 不一樣
解決辦法 后臺(tái)獲取 ClientID
前臺(tái)代碼
<div class="tableList">
<table style="width: 1000px">
<tr style="background-color:#DFECFE">
<th class="style1">
物品名稱
</th>
<th width="80px">
單位
</th>
<th width="80px">
單價(jià)
</th>
<th width="80px">
數(shù)量
</th>
<th width="50px">
小計(jì)
</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>
后臺(tái)代碼
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 ="數(shù)據(jù)名稱"; 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 }

浙公網(wǎng)安備 33010602011771號(hào)