请教一个GridView 通过鼠标点击 确定当前行的问题
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBoundIf e.Row.RowType = DataControlRowType.DataRow Then
'鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'")
'鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'")
e.Row.Attributes.Add("onclick", "window.alert('您选择了第" + e.Row.RowIndex.ToString() + "行');")
End If
End Sub
我可以通过上断代码实现,鼠标点击到GridView任意行,提示处该行是第几行
但怎么能把e.Row.RowIndex.ToString() 这个给到一个变量中,以便其他程序调用
如果直接定义一个变量Dim i as String
再i=e.Row.RowIndex.ToString() 这样得到的值是错误的 --------------------编程问答-------------------- e.Row.Attributes.Add("OnClick","SelectRow(" + e.Row.RowIndex + ")");
function SelectRow(Index)
{
alert(index);
} --------------------编程问答--------------------
function SelectRow(Index)
{
alert(index);
}
这段是在什么地方用,才学ASP.NET 不太懂C#的语句
--------------------编程问答-------------------- Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
这个是在数据绑定的时候促发的,而不是在选择时进行的
'鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'")
'鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'")
就像启动一个控件,控制鼠标一定能够事件 --------------------编程问答--------------------
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim i As Integer = e.Row.RowIndex '直接赋给变量没有问题啊?
If e.Row.RowType = DataControlRowType.DataRow Then
'鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'")
'鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'")
e.Row.Attributes.Add("onclick", "window.alert('您选择了第" + i.ToString + "行');")
End If
End Sub
补充:.NET技术 , VB.NET