单行选择要求:
我当前的gridview只在点击该行时选择该行。因此,如果用户单击第2行然后第3行,则它不是最近的(第3行)而是第2行显示为选中。现在要求是,当用户选择第二行,然后单击第三行时,只应选择第三行而不是第二行。
多行选择要求:
此外,应该允许用户通过单击" CTRL"来选择多行。用鼠标左键单击行。
如何使用JAVASCRIPT实现这一目标?我是Javascript和/或Gridview的新手。有人可以帮我解决这个问题吗?
请记住,我们的申请基于2.0
答案 0 :(得分:0)
var rows_clicked = []
。$('#<%=gvw.ClientID%> tr[id]').click(function() { // row click handler , gridview id = gvw -- assumption // check if it is clicked earlier using IsClicked() // if clicked 1st time, then call OnRowClick, else OnRowDeselect $(this).css("color","red");// set some css to look like selected. });
function OnRowClick()
{
// detect if ctrl+clicked, then save that row's datakey to global
// if it is that, then
rows_clicked.push(datakey);
// and set clicked = true.
$(this).attr("clicked",true);
}
4
function OnRowDeselect()
{
// remove that datakey from `rows_clicked`
}
5
function IsClicked(element)
{
if($(element).attr("clicked")) // clicked is an attr to check if row clicked 1st time or deselected
return true;
else
return false;
}
使用此rows_clicked
并在hiddenfiled中设置,并回发它以在服务器端代码中选择rows
。