<asp:Repeater runat="server" ID="aspRepeater1"
onitemdatabound="aspRepeater1_ItemDataBound">
<HeaderTemplate>
<table class="Width100">
<thead>
<td>
<div>
<span>Name</span>
</div>
</td>
<td>
<div><span>Pin</span></div>
</td>
<td>
<div><span>Icon</span></div>
</td>
<td>
<div><span>Sort Order</span></div>
</td>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr id="trItemRow" runat="server">
<td class="textalignleft">
<div>
<span>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</span>
</div>
</td>
<td>
<div>
<span>
<asp:Label ID="PinLabel" runat="server" Text='<%# Eval("Pin") %>' />
</span>
</div>
</td>
<td>
<div>
<span>
<asp:Label ID="ImageLabel" runat="server" Text='<%# Eval("Image") %>' />
</span>
</div>
</td>
<td>
<div>
<span>
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlOrderOnSelectedIndexChanged" ID="ddlOrder"></asp:DropDownList>
<asp:Label ID="OrderLabel" Visible="false" runat="server" Text='<%# Eval("Order") %>' />
<asp:Label ID="IdLabel" Visible="false" runat="server" Text='<%# Eval("Id") %>' />
</span>
</div>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
onitemdatabound="aspRepeater1_ItemDataBound">
<HeaderTemplate>
<table class="Width100">
<thead>
<td>
<div>
<span>Name</span>
</div>
</td>
<td>
<div><span>Pin</span></div>
</td>
<td>
<div><span>Icon</span></div>
</td>
<td>
<div><span>Sort Order</span></div>
</td>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr id="trItemRow" runat="server">
<td class="textalignleft">
<div>
<span>
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</span>
</div>
</td>
<td>
<div>
<span>
<asp:Label ID="PinLabel" runat="server" Text='<%# Eval("Pin") %>' />
</span>
</div>
</td>
<td>
<div>
<span>
<asp:Label ID="ImageLabel" runat="server" Text='<%# Eval("Image") %>' />
</span>
</div>
</td>
<td>
<div>
<span>
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlOrderOnSelectedIndexChanged" ID="ddlOrder"></asp:DropDownList>
<asp:Label ID="OrderLabel" Visible="false" runat="server" Text='<%# Eval("Order") %>' />
<asp:Label ID="IdLabel" Visible="false" runat="server" Text='<%# Eval("Id") %>' />
</span>
</div>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
cs:
protected void aspRepeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RepeaterItem objItem = e.Item;
HtmlTableRow objItemRow = (HtmlTableRow)objItem.FindControl("trItemRow");
DropDownList ddlOrder = (DropDownList)objItem.FindControl("ddlOrder");
BindOrder(ddlOrder);
Label OrderLabel = (Label)objItem.FindControl("OrderLabel");
ddlOrder.SelectedValue = OrderLabel.Text;
objItemRow.Attributes["onmouseover"] = "this.style.backgroundColor='#D2D2D2';this.style.color='#696969'";
objItemRow.Attributes["onmouseout"] = "this.style.backgroundColor='';this.style.color=''";
objItemRow.Attributes["style"] = "cursor:pointer;";
objItemRow.Attributes["class"] = (objItem.ItemIndex % 2 == 0) ? "" : "TableRowDark";
}
}
private void BindOrder(DropDownList ddlOrder)
{
ddlOrder.DataSource = lstOrder;
ddlOrder.DataBind();
}
protected void ddlOrderOnSelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlOrder = (DropDownList)sender;
//RepeaterItem item = ddlOrder.Parent as RepeaterItem;
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RepeaterItem objItem = e.Item;
HtmlTableRow objItemRow = (HtmlTableRow)objItem.FindControl("trItemRow");
DropDownList ddlOrder = (DropDownList)objItem.FindControl("ddlOrder");
BindOrder(ddlOrder);
Label OrderLabel = (Label)objItem.FindControl("OrderLabel");
ddlOrder.SelectedValue = OrderLabel.Text;
objItemRow.Attributes["onmouseover"] = "this.style.backgroundColor='#D2D2D2';this.style.color='#696969'";
objItemRow.Attributes["onmouseout"] = "this.style.backgroundColor='';this.style.color=''";
objItemRow.Attributes["style"] = "cursor:pointer;";
objItemRow.Attributes["class"] = (objItem.ItemIndex % 2 == 0) ? "" : "TableRowDark";
}
}
private void BindOrder(DropDownList ddlOrder)
{
ddlOrder.DataSource = lstOrder;
ddlOrder.DataBind();
}
protected void ddlOrderOnSelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlOrder = (DropDownList)sender;
//RepeaterItem item = ddlOrder.Parent as RepeaterItem;
HtmlTableCell item = (HtmlTableCell)ddlOrder.Parent;
Label IdLabel = (Label)item.FindControl("IdLabel");
PokOfferCategory oc = null;
PokOfferCategoryController p = new PokOfferCategoryController();
PokOfferCategoryCollection poc = p.FetchByID(IdLabel.Text);
if (poc != null && poc.Count > 0)
{
oc = poc[0];
}
if (oc != null)
{
oc.Order = long.Parse(ddlOrder.SelectedValue);
p.Update(oc.Id, oc.Name, long.Parse(ddlOrder.SelectedValue), oc.Image, oc.Pin, oc.PinOpen, oc.IsDeleted);
}
}
本文转自94cool博客园博客,原文链接http://www.cnblogs.com/94cool/archive/2011/12/19/2293913.html,如需转载请自行联系原作者