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


    aspx:

    <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);
                }
            }

     
  • 相关阅读:
    野路子码农系列(7)近期花里胡哨技巧汇总
    野路子码农系列(6)有关线下验证集选取的思考
    野路子码农(5)Python中的装饰器,可能是最通俗的解说
    野路子码农(4)挖掘机云端部署小试
    野路子码农系列(3)plotly可视化的简单套路
    野路子码农系列(2)Python中的类,可能是最通俗的解说
    野路子码农系列(1) 创建Web API
    pandas技巧两则——列内元素统计和列内元素排序
    Windows环境下Anaconda安装TensorFlow的避坑指南
    让米帝领事馆给你报空气质量(动态网页爬取及简单的数据整理)
  • 原文地址:https://www.cnblogs.com/94cool/p/2293913.html
Copyright © 2020-2023  润新知