作者:劲朋_511 | 来源:互联网 | 2023-09-02 18:28
使用datagrid如何实现单选,并对单选的行实施变色功能
7 个解决方案
Select Row by Clicking Any Column
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dn_voices_webmen/html/webteam11062001.asp
see:
Highlighted Hovering and Anywhere Selecting A DataGrid Row
http://www.dotnetbips.com/displayarticle.aspx?id=205
在之间加上:
-------------------------------------
Private Sub dg1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg1.ItemDataBound
If e.Item.ItemIndex > -1 Then
e.Item.Attributes("onclick") = "Javascript:onc(this);"
End If
End Sub
Html页面代码:
后置代码:
private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int Row = this.dg.CurrentPageIndex*this.dg.PageSize + e.Item.ItemIndex ;
if (e.Item.ItemType ==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem )
{
e.Item.Attributes["onclick"]="EditDataGrid("+(Row+1).ToString()+");";
}
}