asp.net vb query on datagrid and coloring cells

Associate
Joined
24 May 2011
Posts
210
I am not expert in asp.net or web development but do a lot of vbscripting

I have this web page as an aspx file

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, e As EventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
myConnection = New SqlConnection("server=localhost;" & "database=dbname;User ID=user;password=password")
myCommand = new SqlDataAdapter("select server AS 'Server', status AS 'Status',lastchecked AS 'Checkin Date & Time' from VMServerStatus", myConnection)
Dim ds As DataSet = new DataSet()
myCommand.Fill(ds)
MyDataGrid.DataSource = ds
MyDataGrid.DataBind()

End Sub
</script>
<body>
<ASPataGrid id="MyDataGrid" runat="server"
columnwidth="auto" BackColor="#ccccff"
BorderColor="black" ShowFooter="false"
CellPadding=3 CellSpacing="0"
Font-Name="Verdana" Font-Size="7pt"
HeaderStyle-BackColor="#aaaadd" EnableViewState="false"
/>
</aspataGrid>
</body>
</html>

The above displays a status of each server and works as I want to - pulls data from a backend SQL database and displays status of servers, now how do I go about coloring the row in red where the server status field is the text Faulty.
 
When I do similar things with a GridView, I use the methods of the GridView and the codebehind page to handle it. I also use Visual Studio to code mine though and that contains the methods in the GUI, for example GridView.OnRowDataBound method:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx

If you aren't using Visual Studio now I would recommend it. I can code normal HTML in notepad, but a lot of ASP.NET is much easier to do with Visual Studio.

Looks like you want to use the ItemCreated event handler:

http://forums.asp.net/t/1124322.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.onitemcreated.aspx
 
Last edited:
Back
Top Bottom