zoukankan      html  css  js  c++  java
  • 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);
                }
            }

     
  • 相关阅读:
    'live-server' 不是内部或外部命令,也不是可运行的程序 或批处理文件。(解决)
    Node.js安装及环境配置之Windows篇
    开发模式
    IOS13越狱后虚拟定位插件的推荐,relocate
    python,向列表中追加字典,被最后的值覆盖的问题解决办法
    博客园cnblog使用百度统计等站长统计的方法
    IOS解锁哔哩哔哩大会员免费版越狱插件的cydia源
    filza无法安装deb(filza command not found)的解决办法
    Mac 中dock栏图标中文乱码英文正常的解决办法
    关于NVIDIA显卡控制面板中“调整桌面颜色设置”在重启后设置失效的处理方法
  • 原文地址:https://www.cnblogs.com/94cool/p/2293913.html
Copyright © 2011-2022 走看看