By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,560 Members | 2,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,560 IT Pros & Developers. It's quick & easy.

change specific gridview text color

P: 5
I have a small code that shows inactive and active users from the ms access DB.
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" Title="Welcome" %>
  2. <%@ Import Namespace="System.Data" %>
  3. <%@ Import Namespace="System.Data.OleDb" %>
  4. <%@ Import Namespace="System.Drawing" %>
  5.  
  6. <script language="VB" runat="server">
  7.  
  8.     Public Function GetInActiveDays(ByVal strLastLoginDate As String) As Integer
  9.         Dim date1 As Date = New Date()
  10.         Dim date2 As Date = New Date()
  11.         Dim time As TimeSpan
  12.  
  13.         date1 = Date.Parse(strLastLoginDate)
  14.         date2 = Date.Now
  15.         time = date2.Subtract(date1)
  16.  
  17.         Return time.Days
  18.     End Function
  19.  
  20.     Public Function IsInActiveUser(ByVal strLastLoginDate As String) As String
  21.         Dim strStatus As String = "Active"
  22.         Dim FontColor As Color = Color.Blue
  23.  
  24.         If (GetInActiveDays(strLastLoginDate) > 2) Then
  25.             strStatus = "Inactive"
  26.         End If
  27.  
  28.         Return strStatus
  29.     End Function
  30.  
  31.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  32.         lbdt.Text = Date.Now
  33.         BindGridView2()
  34.         Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\origin_timesheet.mdb") & ";")
  35.         myConnection.Open()
  36.  
  37.  
  38.         Dim strQuery As String = "UPDATE Employee SET CurrentLoginDate=?"
  39.         Dim myCommand As New OleDbCommand(strQuery, myConnection)
  40.         myCommand.CommandType = CommandType.Text
  41.  
  42.  
  43.         myCommand.Parameters.Add("@p1", OleDbType.DBDate).Value = Date.Now
  44.         myCommand.ExecuteNonQuery()
  45.         myConnection.Close()
  46.     End Sub
  47.  
  48.     Sub BindGridView2()
  49.         Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\origin_timesheet.mdb") & ";")
  50.         myConnection.Open()
  51.  
  52.  
  53.         Dim strQuery As String = "SELECT * FROM Employee"
  54.         Dim myDataAdapter As New OleDbDataAdapter(strQuery, myConnection)
  55.         Dim ds As New DataSet
  56.  
  57.  
  58.         myDataAdapter.Fill(ds)
  59.         GridView2.DataSource = ds
  60.         GridView2.DataBind()
  61.  
  62.         ds.Dispose()
  63.         myDataAdapter.Dispose()
  64.         ds = Nothing
  65.         myDataAdapter = Nothing
  66.         myConnection.Close()
  67.     End Sub
  68.  
  69. </script>
  70.  
  71. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  72.     <br />
  73.     <br />
  74.     <span
  75.         style="color: #000033"><span style="font-family: Verdana"><span style="font-size: 11pt"><br />
  76.             <br />
  77.             <br />
  78.             <span class="wtxt">Your status is set to: <span style="color: red">Administrator<br />
  79.                 <br />
  80.                 <asp:GridView id="GridView2" runat="server" Width="700px" AllowSorting="True" AutoGenerateColumns="False" Font-Names="Verdana" EmptyDataText="No record found." EmptyDataRowStyle-ForeColor="White" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" Font-Size="8pt" GridLines="None">
  81.     <Columns>   
  82.             <asp:TemplateField HeaderText="Users">
  83.             <ItemStyle Width="400px" VerticalAlign="Top" BorderColor="Transparent"/>
  84.                 <HeaderStyle HorizontalAlign="Left"/>
  85.                 <ItemTemplate>
  86.                     <asp:Label ID="lblUser" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.UserName", "") %>'></asp:Label>
  87.                 </ItemTemplate>
  88.          </asp:TemplateField>  
  89.          <asp:TemplateField HeaderText="Real Name">
  90.             <ItemStyle Width="400px" VerticalAlign="Top" BorderColor="Transparent"/>
  91.                 <HeaderStyle HorizontalAlign="Left"/>
  92.                 <ItemTemplate>
  93.                     <asp:Label ID="lblRealName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.RealName", "") %>'></asp:Label>
  94.                 </ItemTemplate>
  95.          </asp:TemplateField>                  
  96.         <asp:TemplateField HeaderText="Last Login Date">
  97.             <ItemStyle Width="400px" VerticalAlign="Top" BorderColor="Transparent"/>
  98.                 <HeaderStyle HorizontalAlign="Left"/>
  99.                 <ItemTemplate>
  100.                     <asp:Label ID="lblDate" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LastLoginDate", "{0:MM/dd/yyyy}") %>'></asp:Label>
  101.                 </ItemTemplate>
  102.          </asp:TemplateField>
  103.          <asp:TemplateField HeaderText="InActive - More Than 2 Days?">
  104.              <ItemStyle Width="800px" VerticalAlign="Top" BorderColor="Transparent"/>
  105.                  <HeaderStyle HorizontalAlign="Left"/>
  106.                  <ItemTemplate>
  107.                      <asp:Label ID="lblInActive" runat="server" Text='<%# IsInActiveUser(DataBinder.Eval(Container, "DataItem.LastLoginDate", "{0:MM/dd/yyyy}")) %>'></asp:Label>
  108.                  </ItemTemplate>
  109.         </asp:TemplateField>
  110.     </Columns>                
  111.     <EmptyDataRowStyle ForeColor="White" />
  112.                     <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
  113.                     <RowStyle BackColor="#FFFFCC" ForeColor="Black" />
  114.                     <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
  115.                     <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
  116.                     <HeaderStyle BackColor="Gray" Font-Bold="True" ForeColor="Black" Font-Size="8pt" />
  117. </asp:GridView>
  118. <asp:Label ID="lblInActive" runat="server" Text='<%# IsInActiveUser(DataBinder.Eval(Container, "DataItem.Date", "{0:MM/dd/yyyy}")) %>'></asp:Label><br />
  119.                 <span class="wtxt">Current system date &amp; time:</span> 
  120.                 <asp:Label ID="lbdt" runat="server"></asp:Label></span></span></span></span></asp:Content>
Here i wanted to show the inactive users in red .. i think its got something to do with this function, but i dont know the color change code for string.

Expand|Select|Wrap|Line Numbers
  1.     Public Function IsInActiveUser(ByVal strLastLoginDate As String) As String
  2.         Dim strStatus As String = "Active"
  3.         Dim FontColor As Color = Color.Blue
  4.  
  5.         If (GetInActiveDays(strLastLoginDate) > 2) Then
  6.             strStatus = "Inactive"
  7.         End If
  8.  
  9.         Return strStatus
  10.     End Function
Please advise
Thanks in advance ..
Aug 6 '07 #1
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
moved to .NET forum .
Aug 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.