7 个解决方案
#1
datagrid有这样的属性的.
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
#2
用css控制!
<tr onmouseover="this.style.backgroundColor='#e6f1d8'" onmouseout="this.style.backgroundColor='#ffffff'">
sssssssssssssssssssssssssss
</tr>
<tr onmouseover="this.style.backgroundColor='#e6f1d8'" onmouseout="this.style.backgroundColor='#ffffff'">
sssssssssssssssssssssssssss
</tr>
#3
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
BindGrid()
End Sub
Sub BindGrid()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath(".")+"/datagrid.mdb"
Dim myConnection As OleDbConnection
myConnection = New OleDbConnection(connstr)
Dim myDataAdpater As New OleDbDataAdapter("Select Top 10 * from data", myConnection)
Dim myDataSet As DataSet
Try
myDataSet = New DataSet()
'----------------------------------
' Fill the DataSet for the DataBinding of the 2 DataGrid
'----------------------------------
myDataAdpater.Fill(myDataSet)
DataGrid2.DataSource = myDataSet
DataGrid2.DataBind()
Catch SQLEx As OleDbException : Response.Write(SQLEx.Message.ToString())
Catch Ex As Exception : Response.Write(Ex.Message.ToString())
End Try
End Sub
Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method a Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(1).Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
e.Item.Cells(1).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Attributes.Add("onmouseover", "this.style.backgroundColor='#CC3300'")
e.Item.Cells(2).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Style("cursor") = "hand"
'---------------------------------------------------
' Change the Mouse Cursor of a particular Cell (Column) of DataGrid
' (Or you may do it for a whole Row of DataGrid :)
'---------------------------------------------------
e.Item.Cells(3).Style("cursor") = "hand"
'---------------------------------------------------
' Add the OnClick Alert MessageBox to a particular Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(3).Attributes.Add("onclick", "alert('You click at ID: " & e.Item.Cells(0).Text & "!');")
End If
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid2"
runat="server" OnItemDataBound="DataGrid2_ItemDataBound" CellPadding="4" BackColor="White" BorderWidth="1px"
BorderStyle="None"
BorderColor="#CC9966"
EnableViewState="False" AutoGenerateColumns="False">
<SelectedItemStyle font-bold="True" forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
<ItemStyle forecolor="#330099" backcolor="White"></ItemStyle>
<HeaderStyle font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></HeaderStyle>
<FooterStyle forecolor="#330099" backcolor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ProductID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" HeaderText="Product Name"></asp:BoundColumn>
<asp:BoundColumn DataField="QuantityPerUnit" HeaderText="Quantity Per Unit"></asp:BoundColumn>
<asp:BoundColumn DataField="ReorderLevel" HeaderText="Reorder Level"></asp:BoundColumn>
</Columns>
<PagerStyle horizontalalign="Center" forecolor="#330099" backcolor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</form>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
BindGrid()
End Sub
Sub BindGrid()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath(".")+"/datagrid.mdb"
Dim myConnection As OleDbConnection
myConnection = New OleDbConnection(connstr)
Dim myDataAdpater As New OleDbDataAdapter("Select Top 10 * from data", myConnection)
Dim myDataSet As DataSet
Try
myDataSet = New DataSet()
'----------------------------------
' Fill the DataSet for the DataBinding of the 2 DataGrid
'----------------------------------
myDataAdpater.Fill(myDataSet)
DataGrid2.DataSource = myDataSet
DataGrid2.DataBind()
Catch SQLEx As OleDbException : Response.Write(SQLEx.Message.ToString())
Catch Ex As Exception : Response.Write(Ex.Message.ToString())
End Try
End Sub
Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method a Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(1).Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
e.Item.Cells(1).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Attributes.Add("onmouseover", "this.style.backgroundColor='#CC3300'")
e.Item.Cells(2).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Style("cursor") = "hand"
'---------------------------------------------------
' Change the Mouse Cursor of a particular Cell (Column) of DataGrid
' (Or you may do it for a whole Row of DataGrid :)
'---------------------------------------------------
e.Item.Cells(3).Style("cursor") = "hand"
'---------------------------------------------------
' Add the OnClick Alert MessageBox to a particular Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(3).Attributes.Add("onclick", "alert('You click at ID: " & e.Item.Cells(0).Text & "!');")
End If
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid2"
runat="server" OnItemDataBound="DataGrid2_ItemDataBound" CellPadding="4" BackColor="White" BorderWidth="1px"
BorderStyle="None"
BorderColor="#CC9966"
EnableViewState="False" AutoGenerateColumns="False">
<SelectedItemStyle font-bold="True" forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
<ItemStyle forecolor="#330099" backcolor="White"></ItemStyle>
<HeaderStyle font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></HeaderStyle>
<FooterStyle forecolor="#330099" backcolor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ProductID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" HeaderText="Product Name"></asp:BoundColumn>
<asp:BoundColumn DataField="QuantityPerUnit" HeaderText="Quantity Per Unit"></asp:BoundColumn>
<asp:BoundColumn DataField="ReorderLevel" HeaderText="Reorder Level"></asp:BoundColumn>
</Columns>
<PagerStyle horizontalalign="Center" forecolor="#330099" backcolor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</form>
#4
在datagrid的ItemCreated事件里面添加
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='seashell'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#ffffff'");
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='seashell'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#ffffff'");
#5
ItemCreated事件??我是直接用Mydatagrid.Bind()来绑定的啊。。。没有这个事件。。具体怎么写啊
#6
在事件ItemDataBound中添加下面的代码段:
if (e.Item.ItemType ==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem )
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='Green'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes.Add("onmousedown","this.style.cursor='hand';this.style.backgroundColor='red'");
e.Item.Attributes.Add("onmouseup","this.style.backgroundColor=this.getAttribute('BKC');");
}
if (e.Item.ItemType ==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem )
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='Green'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes.Add("onmousedown","this.style.cursor='hand';this.style.backgroundColor='red'");
e.Item.Attributes.Add("onmouseup","this.style.backgroundColor=this.getAttribute('BKC');");
}
#7
private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//上面的代码
}
再在事件申明区中贴[注意dg是DataGrid控件的ID,这里你换成你的ID]
this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
事件申明区:在下面:
private void InitializeComponent()
{
//在这里添加事件申明
}
写得太多,有点太罗嗦得嫌疑!
{
//上面的代码
}
再在事件申明区中贴[注意dg是DataGrid控件的ID,这里你换成你的ID]
this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
事件申明区:在下面:
private void InitializeComponent()
{
//在这里添加事件申明
}
写得太多,有点太罗嗦得嫌疑!
#1
datagrid有这样的属性的.
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
#2
用css控制!
<tr onmouseover="this.style.backgroundColor='#e6f1d8'" onmouseout="this.style.backgroundColor='#ffffff'">
sssssssssssssssssssssssssss
</tr>
<tr onmouseover="this.style.backgroundColor='#e6f1d8'" onmouseout="this.style.backgroundColor='#ffffff'">
sssssssssssssssssssssssssss
</tr>
#3
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
BindGrid()
End Sub
Sub BindGrid()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath(".")+"/datagrid.mdb"
Dim myConnection As OleDbConnection
myConnection = New OleDbConnection(connstr)
Dim myDataAdpater As New OleDbDataAdapter("Select Top 10 * from data", myConnection)
Dim myDataSet As DataSet
Try
myDataSet = New DataSet()
'----------------------------------
' Fill the DataSet for the DataBinding of the 2 DataGrid
'----------------------------------
myDataAdpater.Fill(myDataSet)
DataGrid2.DataSource = myDataSet
DataGrid2.DataBind()
Catch SQLEx As OleDbException : Response.Write(SQLEx.Message.ToString())
Catch Ex As Exception : Response.Write(Ex.Message.ToString())
End Try
End Sub
Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method a Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(1).Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
e.Item.Cells(1).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Attributes.Add("onmouseover", "this.style.backgroundColor='#CC3300'")
e.Item.Cells(2).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Style("cursor") = "hand"
'---------------------------------------------------
' Change the Mouse Cursor of a particular Cell (Column) of DataGrid
' (Or you may do it for a whole Row of DataGrid :)
'---------------------------------------------------
e.Item.Cells(3).Style("cursor") = "hand"
'---------------------------------------------------
' Add the OnClick Alert MessageBox to a particular Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(3).Attributes.Add("onclick", "alert('You click at ID: " & e.Item.Cells(0).Text & "!');")
End If
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid2"
runat="server" OnItemDataBound="DataGrid2_ItemDataBound" CellPadding="4" BackColor="White" BorderWidth="1px"
BorderStyle="None"
BorderColor="#CC9966"
EnableViewState="False" AutoGenerateColumns="False">
<SelectedItemStyle font-bold="True" forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
<ItemStyle forecolor="#330099" backcolor="White"></ItemStyle>
<HeaderStyle font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></HeaderStyle>
<FooterStyle forecolor="#330099" backcolor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ProductID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" HeaderText="Product Name"></asp:BoundColumn>
<asp:BoundColumn DataField="QuantityPerUnit" HeaderText="Quantity Per Unit"></asp:BoundColumn>
<asp:BoundColumn DataField="ReorderLevel" HeaderText="Reorder Level"></asp:BoundColumn>
</Columns>
<PagerStyle horizontalalign="Center" forecolor="#330099" backcolor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</form>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Data" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
BindGrid()
End Sub
Sub BindGrid()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Server.MapPath(".")+"/datagrid.mdb"
Dim myConnection As OleDbConnection
myConnection = New OleDbConnection(connstr)
Dim myDataAdpater As New OleDbDataAdapter("Select Top 10 * from data", myConnection)
Dim myDataSet As DataSet
Try
myDataSet = New DataSet()
'----------------------------------
' Fill the DataSet for the DataBinding of the 2 DataGrid
'----------------------------------
myDataAdpater.Fill(myDataSet)
DataGrid2.DataSource = myDataSet
DataGrid2.DataBind()
Catch SQLEx As OleDbException : Response.Write(SQLEx.Message.ToString())
Catch Ex As Exception : Response.Write(Ex.Message.ToString())
End Try
End Sub
Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method a Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(1).Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
e.Item.Cells(1).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Attributes.Add("onmouseover", "this.style.backgroundColor='#CC3300'")
e.Item.Cells(2).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Style("cursor") = "hand"
'---------------------------------------------------
' Change the Mouse Cursor of a particular Cell (Column) of DataGrid
' (Or you may do it for a whole Row of DataGrid :)
'---------------------------------------------------
e.Item.Cells(3).Style("cursor") = "hand"
'---------------------------------------------------
' Add the OnClick Alert MessageBox to a particular Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(3).Attributes.Add("onclick", "alert('You click at ID: " & e.Item.Cells(0).Text & "!');")
End If
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid2"
runat="server" OnItemDataBound="DataGrid2_ItemDataBound" CellPadding="4" BackColor="White" BorderWidth="1px"
BorderStyle="None"
BorderColor="#CC9966"
EnableViewState="False" AutoGenerateColumns="False">
<SelectedItemStyle font-bold="True" forecolor="#663399" backcolor="#FFCC66"></SelectedItemStyle>
<ItemStyle forecolor="#330099" backcolor="White"></ItemStyle>
<HeaderStyle font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></HeaderStyle>
<FooterStyle forecolor="#330099" backcolor="#FFFFCC"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ProductID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" HeaderText="Product Name"></asp:BoundColumn>
<asp:BoundColumn DataField="QuantityPerUnit" HeaderText="Quantity Per Unit"></asp:BoundColumn>
<asp:BoundColumn DataField="ReorderLevel" HeaderText="Reorder Level"></asp:BoundColumn>
</Columns>
<PagerStyle horizontalalign="Center" forecolor="#330099" backcolor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</form>
#4
在datagrid的ItemCreated事件里面添加
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='seashell'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#ffffff'");
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='seashell'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#ffffff'");
#5
ItemCreated事件??我是直接用Mydatagrid.Bind()来绑定的啊。。。没有这个事件。。具体怎么写啊
#6
在事件ItemDataBound中添加下面的代码段:
if (e.Item.ItemType ==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem )
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='Green'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes.Add("onmousedown","this.style.cursor='hand';this.style.backgroundColor='red'");
e.Item.Attributes.Add("onmouseup","this.style.backgroundColor=this.getAttribute('BKC');");
}
if (e.Item.ItemType ==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem )
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='Green'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes.Add("onmousedown","this.style.cursor='hand';this.style.backgroundColor='red'");
e.Item.Attributes.Add("onmouseup","this.style.backgroundColor=this.getAttribute('BKC');");
}
#7
private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//上面的代码
}
再在事件申明区中贴[注意dg是DataGrid控件的ID,这里你换成你的ID]
this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
事件申明区:在下面:
private void InitializeComponent()
{
//在这里添加事件申明
}
写得太多,有点太罗嗦得嫌疑!
{
//上面的代码
}
再在事件申明区中贴[注意dg是DataGrid控件的ID,这里你换成你的ID]
this.dg.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_ItemCommand);
事件申明区:在下面:
private void InitializeComponent()
{
//在这里添加事件申明
}
写得太多,有点太罗嗦得嫌疑!