2008-10-09 49 views
0

任何人都知道如何解析DOM並確定在ASP.NET ListView中選擇了哪一行?我可以通過Silverlight中的HtmlElement與DOM進行交互,但我無法找到指示該行被選中的屬性。DOM解析

以供參考,該管理方法工作正常的ASP.NET列表框

var elm = HtmlPage.Document.GetElementById(ListBoxId); 

foreach (var childElm in elm.Children) 
{ 
    if (!((bool)childElm.GetProperty("Selected"))) 
    { 
     continue; 
    } 
} 

回答

0

我沒有我的開發環境來測試這一點,但你能在電話會議上的getProperty(「的selectedIndex」) ListBoxID元素?然後從中找出哪個孩子被選中,並使用elm.Children返回該孩子。

編輯:今天早上得到了我的開發環境,並做了一些測試。下面的代碼片段,對我的工作:

HtmlElement elem = HtmlPage.Document.GetElementById("testSelect"); 
int index = Convert.ToInt32(elem.GetProperty("selectedIndex")); 
var options = (from c in elem.Children 
       let he = c as HtmlElement 
       where he.TagName == "option" 
       select he).ToList(); 

output.Text = (string)options[index].GetProperty("innerText"); 

當然,你必須「textSelect」更改爲您選擇的HTML元素的名稱。 linq查詢是必需的,因爲Children屬性由ScriptableObjects組成,只有大約一半是您關心的選項元素。

1

如果你的列表視圖有選擇行特定的CSS類,你可以嘗試在它

1

提供應罰款的建議馬修過濾。既然你提到了行,我會說添加一個id到你的ListView中的tr元素,然後你可以用jQuery找到它。

所以,

<tr id='selectedRow'> 
...... 
</tr> 

$(document).ready(function() { 
    $("#selectedRow").click(function() { 
     alert('This is the selected row'); 
    }); 

});