比如我现在显示数据是 xml->dataset->gridview
如果我xml数据变化了我想网格背景变色,请问怎么实现?举例-
all.xml文件:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Titles>
<id>112107</id>
<ts>0.65</ts>
<ss>0.74</ss>
<es>1.25</es>
</Titles>
</NewDataSet>Dim ds As New DataSet
ds.ReadXml("D:\all.xml")
GridView1.DataSource = ds.Tables(0).DefaultView
GridView1.DataBind()显示在Gridview控件上如下:
| id | ts | ss | es |
|112107|0.65|0.74|1.25|如果现在all.xml文件 <ts>0.65</ts> 变成了 <ts>0.75</ts>
那么Gridview中|0.65|变成|0.75|这个网格背景色就变成绿色。请问怎么实现?
如果我xml数据变化了我想网格背景变色,请问怎么实现?举例-
all.xml文件:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Titles>
<id>112107</id>
<ts>0.65</ts>
<ss>0.74</ss>
<es>1.25</es>
</Titles>
</NewDataSet>Dim ds As New DataSet
ds.ReadXml("D:\all.xml")
GridView1.DataSource = ds.Tables(0).DefaultView
GridView1.DataBind()显示在Gridview控件上如下:
| id | ts | ss | es |
|112107|0.65|0.74|1.25|如果现在all.xml文件 <ts>0.65</ts> 变成了 <ts>0.75</ts>
那么Gridview中|0.65|变成|0.75|这个网格背景色就变成绿色。请问怎么实现?
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim ds As New DataSet
ds.ReadXml("D:\all.xml")
GridView1.DataSource = ds.Tables(0).DefaultView
GridView1.DataBind()
End Sub<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ToXML.aspx.vb" Inherits="ToXML" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="15000" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel> </form>
</body>
</html>
请问应该怎么改才能实现我说的效果?谢谢!
function dd(result)
{
if((result==null)||(result==""))
{
return;
}
else
{
if(result==olddata)
{
return;
}
else
{
alert("数据已经改变! ")
return;
}
}
}
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Titles>
<id>112107</id>
<ts>0.65</ts>
<ss>0.74</ss>
<es>1.25</es>
</Titles>
</NewDataSet>
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim ds As New DataSet
ds.ReadXml("D:\all.xml")
GridView1.DataSource = ds.Tables(0).DefaultView
GridView1.DataBind()
End Sub<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ToXML.aspx.vb" Inherits="ToXML" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="15000" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel> </form>
</body>
</html>
如果现在all.xml文件 <ts>0.65</ts> 变成了 <ts>0.75</ts>
那么Gridview中|0.65|变成|0.75|这个网格背景色就变成绿色。请问怎么实现?
Dim ds As New DataSet
ds.ReadXml("D:\all.xml")
GridView1.DataSource = ds.Tables(0).DefaultView
GridView1.DataBind() ViewState("myDS") = ds'绑定后把旧数据存起来
End SubProtected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowIndex > -1 And Not ViewState("myDS") Is Nothing Then
Dim ds As DataSet = ViewState("myDS")
For i As Integer = 0 To e.Row.Cells.Count - 1
If e.Row.Cells(i).Text <> ds.Tables(0).Rows(e.Row.DataItemIndex)(i).ToString() Then
e.Row.Cells(i).ForeColor = Drawing.Color.Red
End If
Next
End If
End Sub
上面这些简单代码能够解决行数不变的情况,如果行数是可变的,并且id是唯一标识,则需要改写RowDataBound:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowIndex > -1 And Not ViewState("myDS") Is Nothing Then
Dim ds As DataSet = ViewState("myDS")
Dim id As String = e.Row.Cells(0).Text
Dim rows() As DataRow = ds.Tables(0).Select("[id]='" & id & "'") '尝试在旧数据集中找到当前id的行
'如果没有找到,当前行就用不同的颜色显示
If rows.Length = 0 Then
e.Row.ForeColor = Drawing.Color.Red
Else
For i As Integer = 0 To e.Row.Cells.Count - 1
If e.Row.Cells(i).Text <> rows(0)(i).ToString() Then
e.Row.Cells(i).ForeColor = Drawing.Color.Orange
End If
Next
End If
End If
End Sub
你的代码我运行了,数据变化后没有变色。你可以试试看