2 回答
TA贡献1784条经验 获得超9个赞
直接贴代码了:
<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);
}
}
- 2 回答
- 0 关注
- 1602 浏览
添加回答
举报