Repeater中使用Button

废话不多直接贴代码

前台代码:

<asp:Repeater ID="Repeater3" runat="server">

            <ItemTemplate>

                <div class="line_item" ><a href="line.aspx?line_id=<%#Eval("id") %>"><%#Eval("title") %></a><span style="color: rgb(136, 136, 136); float: right; margin-right: 90px;"><%#Eval("price") %>元/人</span>

                    <asp:HiddenField ID="lineId" runat="server" Value='<%#Eval("id")%>' />

                <asp:Button ID="Button1" OnClick="Advance"  style="float: right; margin-right: -120px; margin-top: -4px;" runat="server" Text="预定" /></div>

            </ItemTemplate>

        </asp:Repeater>

后台代码:

#region 预定

    protected void Advance(object sender, EventArgs e) {

        Button bt = sender as Button;

        RepeaterItem ri = bt.Parent as RepeaterItem;

        HiddenField tx = ri.FindControl("lineId") as HiddenField;

        if (!object.Equals(tx, null)) 

        { Response.Write(tx.Value); }

    }

    #endregion

你可能感兴趣的:(button)