repeater中绑定dropdownlist事件

 

前台

<asp:DropDownList ID="DDL_Gly" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL_Gly_Change"></asp:DropDownList>
<asp:HiddenField ID="hfid" Value=<%#Eval("yy") %> runat="server" />

 

后台

protected void DDL_Gly_Change(object sender, EventArgs e)
{
DropDownList drd = sender as DropDownList;
Repeater rps = drd.Parent.Parent as Repeater;
int n = ((RepeaterItem)drd.Parent).ItemIndex;//行号
HiddenField hid = (HiddenField)(rps.Items[n].FindControl("hfid"));
string ss= hid.Value;
int yy= Convert.ToInt32(drd.SelectedValue);

//已经拿到了id,可以进行操作

if (Weibozhu.UpdateGly(Convert.ToInt32(ss), yy))
{
Response.Write("<script language=javascript>parent.location.reload();</script>");
//Response.Write("<script language=javascript>alert(' 修改成功');</script>");
}
else Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language=javascript>alert(' 失败');</script>", false);
}

posted @ 2013-02-26 09:58  王者杂货铺  阅读(258)  评论(0编辑  收藏  举报