DOM解析

问题描述:

任何人都知道如何解析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; 
    } 
} 

我没有我的开发环境来测试这一点,但你能在电话会议上的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组成,只有大约一半是您关心的选项元素。

如果你的列表视图有选择行特定的CSS类,你可以尝试在它

提供应罚款的建议马修过滤。既然你提到了行,我会说添加一个id到你的ListView中的tr元素,然后你可以用jQuery找到它。

所以,

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

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

});