大哥们 帮我看看这个小问题 呀
repeart控件,前面是个下拉框的input的select标签,怎么实现下拉框中的值更换了之后 后面数据也跟着变化呀
直接贴代码了:
<ItemTemplate>
<tr >
<td>
<asp:DropDownList ID="DListNewsIsShow" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DListNewsIsShow_SelectedIndexChanged">
<asp:ListItem Value="1">是</asp:ListItem>
<asp:ListItem Value="0">否</asp:ListItem>
</asp:DropDownList><asp:Label ID="LabId" runat="server" Visible="false" Text='<%# Eval("id") %>'></asp:Label>
</td>
</ItemTemplate>
...
//遍历Rpt中DListNewsIsShow的数据读取
protected void RptNew_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
{
DataRowView rowv = (DataRowView)e.Item.DataItem;
DropDownList DListNewsIsShow = (DropDownList)e.Item.FindControl("DListNewsIsShow");
DListNewsIsShow.Items.FindByValue(rowv["isshow"].ToString()).Selected = true;
}
}
//异步更新新闻是否显示
protected void DListNewsIsShow_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DListFNewsIsShow = sender as DropDownList;
RepeaterItem item = DListFNewsIsShow.Parent as RepeaterItem; //转为所在Item
Label LabFId = item.FindControl("LabId") as Label; //查找
NewsInfo newsInfoRpt = new NewsInfo();
newsInfoRpt.Id = LabFId.Text.ToString();
newsInfoRpt.IsShow = Convert.ToInt16(DListFNewsIsShow.SelectedValue.ToString());
if(news.Update(newsInfoRpt,"1")<=0)
{
ScriptManager.RegisterStartupScript(UpDPanelRptNews, typeof(UpdatePanel), "JsAlert", "alert('对不起,更新失败!!')", true);
}
}
用服务器控件DropdownList或用ajax来操作
用DropdowList服务器端控件,并将AutoPostback属性设为true,然后添加change事件,在change事件中,强转 var ddl= sender as DropdownList;
然后通过ddl.Parent().FindControl("") 找到你要更新的同一行的某个控件,假设为control1, 最后根据需要取下拉列表选中项的value值将所需要更新数据的控件control1进行数据的更新,以达到联动的效果。
ajax实现!如果嫌麻烦。用dropdownlist+updatePanel来实现!