![](/img/trans.png)
[英]Container.DisplayIndex not working with paging in ASP.NET
[英]Working with C# ASP.NET ListView, Unable to return DisplayIndex
在我的研究,我發現我的問題(見下文),但不幸的是,這些解決方案的一些解決方案不會為網站工作,因為它們都靶向的WinForms。
我需要在MouseOver事件上獲取ListViewItem的DisplayIndex。 我不想做諸如通過自定義html屬性(例如'index="0"'
)呈現頁面時添加索引,然后在__doPostBack()
函數中使用該'index="0"'
事情。
我有一個updatepanel
和一個listview
,它們都在一個絕對的div中,當鼠標懸停在另一個listview
項中的Label上時,我希望能夠使用與懸停的項相關的數據來更新updatepane
l 。 這背后的整個想法是,我想使用一個容器div並在listview
項上的每次mouseover
時隱藏/顯示它。
因此,基本上,當鼠標懸停時,假設在listview id =“ lv”內的listviewitem中具有ID =“ hi”的標簽,我想獲取該listviewitem ID以在另一個updatepanel中更新另一個listview。
我不確定這是否會引起混淆,但僅獲取DisplayIndex
的listviewitem
的DisplayIndex
並將其用於__doPostBack
函數即可解決我的問題。
感謝您的時間!
您可以在標簽后面添加一個按鈕,在該按鈕上設置CommandName="Select"
,然后使用display:none
樣式將其隱藏。 在ListView的ItemDataBound事件處理程序中,您可以添加onmouseover屬性來標記以觸發這些按鈕單擊並處理ListView的SelectedIndexChanging事件,您自然可以獲取所選項目的索引。
標記:
<ItemTemplate>
<li>
<asp:Label runat="server" ID="Label1" Text='<%# Container.DataItem.ToString() %>' />
<asp:Button runat="server" ID="SelectButton" CommandName="Select" style="display:none;" />
</li>
</ItemTemplate>
碼:
void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
var label = e.Item.FindControl("Label1") as Label;
if (label != null)
{
var selectButton = e.Item.FindControl("SelectButton") as Button;
label.Attributes["onmouseover"] = ClientScript.GetPostBackEventReference(selectButton, "");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.