我如何在 ASP.NET 后面的代码中使用 Content.ItemIndex?
How could I use Content.ItemIndex in Code behind ASP.NET?
我在 ASPX 上有这段代码
<div class="col-md-8 col-sm-12 text-poster-box">
<p tabindex="1">
<asp:Label ID="LabelResultName" CssClass="h3" runat="server">Name: <%# Eval("Name") %> </asp:Label>
</p>
<p tabindex="2">
<asp:Label ID="LabelResultPrice" CssClass="h3" runat="server">Price: <%# Eval("Price") %>$ </asp:Label>
</p>
<p tabindex="3">
<asp:Label ID="LabelResultSalePrice" runat="server" CssClass="h3" Visible='<%#Eval("SalePrice").ToString() != "" ? true : false %>'>New Price: <%#Eval("SalePrice")%>$</asp:Label>
</p>
<p tabindex="4">
<asp:Label ID="LabelSize" CssClass="h3" runat="server">Size: <%# Eval("Size") %></asp:Label>
</p>
<p tabindex="5">
<asp:Button ID="ButtonRemove" runat="server" CssClass="btn btn-primary-c wishlist" Text="Remove" OnClick="ButtonRemove_Click" />
</p>
<p tabindex="6">
<asp:Label ID="lblListNumber" Text='<%# Container.ItemIndex%>' runat="server" Visible="true" /></td>
</p>
</div>
我想在代码隐藏中使用 Content.ItemIndex
给出的数字,这样我就可以从 List<T>
中删除这样的对象:
MyList.RemoveAt("value received from Content.ItemIndex")
我不知道这是否可能?
我会为转发器使用 onitemcommand。
例如:
<asp:Repeater id="rptYourPages" runat="server" onitemcommand="rpt_ItemCommand">
然后将带有记录 ID 的 Eval 的 CommandArgument 添加到按钮。
CommandArgument='<%# Eval("ProductID") %>'
您的按钮代码如下所示:
<asp:Button ID="ButtonRemove" runat="server" CssClass="btn btn-primary-c wishlist" Text="Remove" CommandArgument='<%# Eval("ProductID") %>' />
您不需要 OnClick。
在代码隐藏文件中:
protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string sProductID = e.CommandArgument.ToString();
// Write your logic here...
}
希望这对您有所帮助。
我在 ASPX 上有这段代码
<div class="col-md-8 col-sm-12 text-poster-box">
<p tabindex="1">
<asp:Label ID="LabelResultName" CssClass="h3" runat="server">Name: <%# Eval("Name") %> </asp:Label>
</p>
<p tabindex="2">
<asp:Label ID="LabelResultPrice" CssClass="h3" runat="server">Price: <%# Eval("Price") %>$ </asp:Label>
</p>
<p tabindex="3">
<asp:Label ID="LabelResultSalePrice" runat="server" CssClass="h3" Visible='<%#Eval("SalePrice").ToString() != "" ? true : false %>'>New Price: <%#Eval("SalePrice")%>$</asp:Label>
</p>
<p tabindex="4">
<asp:Label ID="LabelSize" CssClass="h3" runat="server">Size: <%# Eval("Size") %></asp:Label>
</p>
<p tabindex="5">
<asp:Button ID="ButtonRemove" runat="server" CssClass="btn btn-primary-c wishlist" Text="Remove" OnClick="ButtonRemove_Click" />
</p>
<p tabindex="6">
<asp:Label ID="lblListNumber" Text='<%# Container.ItemIndex%>' runat="server" Visible="true" /></td>
</p>
</div>
我想在代码隐藏中使用 Content.ItemIndex
给出的数字,这样我就可以从 List<T>
中删除这样的对象:
MyList.RemoveAt("value received from Content.ItemIndex")
我不知道这是否可能?
我会为转发器使用 onitemcommand。 例如:
<asp:Repeater id="rptYourPages" runat="server" onitemcommand="rpt_ItemCommand">
然后将带有记录 ID 的 Eval 的 CommandArgument 添加到按钮。
CommandArgument='<%# Eval("ProductID") %>'
您的按钮代码如下所示:
<asp:Button ID="ButtonRemove" runat="server" CssClass="btn btn-primary-c wishlist" Text="Remove" CommandArgument='<%# Eval("ProductID") %>' />
您不需要 OnClick。
在代码隐藏文件中:
protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string sProductID = e.CommandArgument.ToString();
// Write your logic here...
}
希望这对您有所帮助。