473,756 Members | 7,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change specific gridview text color

5 New Member
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
1 2612
jhardman
3,406 Recognized Expert Specialist
moved to .NET forum .
Aug 7 '07 #2

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

Similar topics

3
3009
by: dm1608 | last post by:
I have a GridView that is using an ObjectDataSource to populate. One of my columns is named "Status" and can have a value of "Complete", "Error", "Active", and "Unknown". I would like to have the text for the word "Error" displayed in RED letters. How can I do this with a GridView control?
1
1507
by: needin4mation | last post by:
protected void Page_Load(object sender, EventArgs e) { TextBox mpTextBox = (TextBox)(Master.FindControl("txtFreeSearch")); Response.Write("mp" + mpTextBox.Text); //only works the second time }
3
3313
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
0
3667
by: Dan | last post by:
Issue making textbox visible based on specific input from a radio button list in an EditItemTemplate I want to setup a gridview that when in edit mode and when the user selects "Other" from a radiolist that a text box will appear and the user can input text. I can get the textbox to appear after selecting other in the radiolist; however, the selected value in the radiolist disappears. I believe this is due to the databind call.
3
1577
by: Ashton | last post by:
Hello, I have a GridView; once the page is loaded I can sort it just fine, I can sort it as many times as I would like, I can sort any of the columns. After clicking on Search and the GridView is updated with new data the sort does not work. I'm using C# and Ajax for the implementation, below is the code,
4
3485
by: =?Utf-8?B?Y2hyaXM=?= | last post by:
I have a perent gridview which includes in a template field a child gridview. Child gridview includes command buttons for opening different windows based on its row selected. I used the code below. The event for RowDataBound is executed, rows get different color, but event for RowCommand is not executed. What could be the problem ? Thanks a lot in advance.
2
2114
by: Blasting Cap | last post by:
I've got a gridview (that I converted over from a datagrid, which had been working properly), that is doubling up the number of rows returned. When it was running as a datagrid, the same code sent back the proper number of rows. The only thing different I am doing is to display the number of rows returned in the footer of the gridview. The Bindgrid is as follows: Sub BindGrid() Session("reportlevel") = Session("availabilityrptlevel")
0
1567
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I need to have a column in a gridview that cycles through a set of comma delimited values i.e. if you imagine a column where in one row the value might be "111,222" and in the next row it might be "111,222,333,444". Instead of displaying the whole string, I need to split the string by the comma delimeter and show each value long enough so that every value will be
1
1982
by: Ben | last post by:
Hi, The gridview contains a radiobuttonlist with boolean values (true/false) coming from a database. In normal mode, the gridview displays True or False for that field. What i want is to change True' and 'False' by 'Yes' and 'No' in normal mode. I tried this, but still get True / False. Thanks for help
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.