比如我现在显示数据是 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|这个网格背景色就变成绿色。请问怎么实现?

解决方案 »

  1.   

    也就是说xml里面的数据是不断变化的?一旦变化了这边就变成绿色??
      

  2.   

    Gridview这边要不断地去检测xml是否变化??
      

  3.   

    是的,我用了atlas的timer  定时自动变化数据,现在怎样实现这个变色?
      

  4.   

    如果是这样的话,那就是在每次检测的过程中,定义一个变量,ss,比如说你的例子,检测之后将取出的数据,比如说0.74赋值给ss,下一次检测的时候,比较取出的数据是否和ss(0.74)相同,如果相同,就不变颜色,如果不同,就变色,并且将新取出的数据赋给ss
      

  5.   

    我的是这样的,请看:
    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>
    请问应该怎么改才能实现我说的效果?谢谢!
      

  6.   

    var olddata;
             function dd(result)
             {
                if((result==null)||(result==""))
              {
                return;
              }
              else 
              {
                if(result==olddata)
                {
                 return;
                }
                else
                {
                 alert("数据已经改变! ")
                 return;
                }
               
              }
             }
      

  7.   

    我的是这样的,请看: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>
    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|这个网格背景色就变成绿色。请问怎么实现?
      

  8.   

    请问可以写在 GridView1_RowDataBound 事件里判断吗?
      

  9.   

    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()        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
      

  10.   

    to:Eddie005(♂) №.零零伍 (♂) 
    你的代码我运行了,数据变化后没有变色。你可以试试看
      

  11.   

    还没解决啊,那我建议你在session中或者别的地方对改变了的保留一下