<tr>
<td class="bqleft">
<asp:TextBox ID="TextBox11" runat="server" Style="display: none">news</asp:TextBox>
类型:</td>
<td class="bqright">
<asp:DropDownList ID="DropDownList6" runat="server" Height="16px" Width="83px">
<asp:ListItem Value="1">--旺铺--</asp:ListItem>
<asp:ListItem Value="2">--写字楼--</asp:ListItem>
<asp:ListItem Value="3">--招商引资--</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList5" runat="server" Height="16px" Width="86px">
</asp:DropDownList>
</td>
</tr> 初始化DropDownList5 if (!IsPostBack)
{
ViewState["retu"] = Request.UrlReferrer.ToString();
DropDownList5.DataTextField = "typename";
DropDownList5.DataValueField = "id";
DropDownList5.DataSource = Common.GetKyCms("select * from hddtype where father_id=1 order by id desc");
DropDownList5.DataBind();
}DropDownList6的change事件$(document).ready(function () { $("#DropDownList6").change(function () {
$.ajax({
type: "post",
url: "../../ASHX/type.ashx",
data: { father_id: $("#DropDownList6").val() },
success: function (data) {
$("#DropDownList5").html(data);
}, error: function () {
alert("发生未知错误!请联系管理员!");
}
});
});
});一般处理程序 type.ashxpublic void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Charset = "gbk";
int father_id = 1;
if (!string.IsNullOrEmpty(context.Request["father_id"]))
{
father_id = Convert.ToInt32(context.Request["father_id"]);
string sql = "select * from hddtype where father_id=" + father_id + " order by id asc";
DataTable dt = Common.GetKyCms(sql);
string htmltext = string.Empty;
bool isfirst = true;
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
if (isfirst)
{
htmltext += "<option value=\"" + row[0].ToString() + "\" selected=\"selected\">" + row[1] + "</option>";
isfirst = false;
}
else
htmltext += "<option value=\"" + row[0].ToString() + "\">" + row[1] + "</option>";
}
}
context.Response.Write(htmltext.ToString());
context.Response.End(); //结束流
}
}
$("#DropDownList5").html(data); //我觉得是不是异步提交的时候出现了问题。
}, DropDownList5.DataTextField = "typename";
DropDownList5.DataValueField = "id";
DropDownList5.DataSource = Common.GetKyCms("select * from hddtype where father_id=1 order by id desc");
DropDownList5.DataBind();
DropDownList5.DataValueField = "id";
DropDownList5.DataSource = Common.GetKyCms("select * from hddtype where father_id=1 order by id desc");
DropDownList5.DataBind(); 的第一个值。很奇怪
看来可以用hidden。
加入我选择dropdownlist6但是直接保存的话,hidden就是为空了,呵呵。
除非我在dropdownlist5前面加个“请选择”