Repeater中绑定DropDownList及找出对应列ID

简介:
<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>

 

 

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;      

    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,如需转载请自行联系原作者

相关文章
easyUI 中datagrid 返回列隐藏方法
easyui的datagrid方法返回的列,有的值不需要显示可以使用hidden(属性进行隐藏)   columns : [ [{ field : 'bailClass', title : '类别', ...
928 0
|
JavaScript .NET 开发框架
给Repeater控件里添加序号的5种方法
给Repeater控件里添加序号的5种方法   .net是目前非常热门的一种程序编译语言,在.net培训中的众多知识点中,给Repeater控件里添加序号的5种方法是非常重要的一个。下面就由达内的老师为大家介绍一下这方面的内容。
1202 0