Gridview每日更新

时间:2013-10-10 18:17:38

标签: asp.net vb.net gridview

我目前在ASP.NET VB中有一个Gridview,您可以在其中选择一行,然后将数据传输到下一页以进行输入。我的问题是有一个简单的方法,我可以在有人输入此行和同一天的信息后突出显示该行。因此,如果有人今天为某人输入数据,那么明天突出显示将在下一个日历日消失。我感谢任何帮助。

这就是我现在所拥有的。

    Public Sub Get_GV()
    ' Fills Gridview with data selected from dropdown-area

    DSADT.SelectParameters("Area").DefaultValue = DDArea.SelectedValue
    Dim dv As DataView = DSconnect.Select(DataSourceSelectArguments.Empty)
    GridView1.DataSource = dv
    GridView1.DataBind()

End Sub

Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated

    ' Allows you to "select"/Highlight a row without a select button
    If e.Row.RowType = DataControlRowType.DataRow Then
        e.Row.Attributes("onmouseover") = "this.style.cursor='pointer';this.style.backgroundColor = '#87CEFF';"
        e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';this.style.backgroundColor = '#FFFFFF';"
        e.Row.Attributes("OnClick") = Me.Page.ClientScript.GetPostBackClientHyperlink(Me.GridView1, "Select$" & e.Row.RowIndex)
    End If

End Sub


Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
    Dim sb As New System.Text.StringBuilder()

    'Submits data to next page
    Response.Redirect("RoundingEntry.aspx?Room=" & GridView1.SelectedRow.Cells(1).Text & "&Name=" & GridView1.SelectedRow.Cells(2).Text & "&Rounder=" & DDRounder.SelectedValue & "&Area=" & DDArea.SelectedValue)

End Sub

2 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

Private Sub FormatMyGridView _
               (ByVal sender As Object, _
                ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
           Handles GridView1.RowDataBound

      Dim drItems As DataRow

         If e.Row.RowType = DataControlRowType.DataRow Then

         drRequest =DirectCast(e.Row.DataItem, System.Data.DataRowView).Row

         ' get your field from DataItem
         ' format the row based on field value:
         if drItems.YourFieldDateTime.Date = DateTime.Date

           ' hilight the row

           e.Row.BackColor = System.Drawing.Color.Red;

       End If    

   End Sub

答案 1 :(得分:0)

您需要在查询返回的数据中包含最后修改日期以绑定网格视图,然后您可以处理RowDataBound事件以检查每行的最后修改日期与今天的日期,如下:

代码隐藏:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    ' Only check the last modified date for data rows, ignore header and footer rows
    If e.Row.RowType = DataControlRowType.DataRow Then
        ' Get the last modified date for each row, possibly in a hidden field control and compare it to today's date

    End If
End Sub

标记:

<asp:gridview id="GridView1" 
    onrowdatabound="GridView1_RowDataBound" 
    runat="server">
  </asp:gridview>

onrowdatabound="CustomersGridView_RowDataBound"