如题,摘抄代码如下:
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_ItemDataBound">
<ItemTemplate>
<tr class="tr1" onmouseover="javascript:changebg(this,0)" onmouseout="javascript:changebg(this,1)">
<td align='center' valign='middle'>
<asp:DropDownList CssClass="des" runat="server" ID="ddlDes"/>
</td>
<td align='center' valign='middle'>
<asp:DropDownList runat="server" ID="ddlMaterial">
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<script type="text/javascript">
$(function() {
$(".des").change(function () {
var children = $(this).parent().next().find("select");
children.empty().append($("<option value='-1'>-请选择-</option>"));
if ($(this).val() != '-1') {
$.get("../handler/StoreHandler.ashx", { type: "Material", id: $(this).val() }, function (data) {
var objs = eval("(" + data + ")");
if (objs.length > 0) {
for (var i = 0; i < objs.length; i++) {
var result = $("<option></option>");
result.val(objs[i].ID);
result.text(objs[i].Name);
children.append(result);
}
}
});
}
});
})
</script>
后台处理:
foreach (RepeaterItem item in Repeater2.Items)
{
DropDownList ddlDes = item.FindControl("ddlDes") as DropDownList;
if (ddlDes == null) continue;
DropDownList ddlMaterial = item.FindControl("ddlMaterial") as DropDownList;
if (ddlMaterial == null) continue;
var m = new TModel_NoStandardADModel();
m.DesId = int.Parse(ddlDes.Text);
//m.MaterialId=??
}
添加隐藏域,用隐藏域中转下拉框的值