I have an issues here, that sounds very complicated for a novice user like me :-(.
I am developing a website for my company to automate Windows Server Administration. Using this web based tool one can query windows server details like Hardware/Software/Ping Status/Network Configuration etc. To get these details I have an ASPX page with a GridView control placed on it. There are few text boxes for getting input from the user and few buttons to perform actions.
Coming to the issue:
The GridView control placed on the aspx page is used as common way to display output from any of the several buttons on the page. I am collecting the couput details in a DataTable during the code execution and finally binding the DataTable to the GridView to display the results.
There are different functions attached with each button click event. Every function is using different structure of columns to display output based on the purpose. For example: function to display ping status will use columns - ServerName, IPAddress, FQDN, PingStatus; whereas the function to display OS details will have columns such as - ServerName, OperatingSystem, ServicePack, SerialNumber, LastBootUp. Thus the same GridView will have different columns at different times.
Based on the value criterias defined in different functions I need to highlight the rows in GridView in different color (yellow background). For example: In the function to display windows Service details I need to highlight rows where Service status is Stopped. Whereas in the function to display Disk Usage I need to highlight the rows where disk free space percentage column is having values below 10%.
I have searched the web and found below (event handler) function to highlight the rows based on the cell value but it is depending on the RowDataBound Event.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.BackColor = Color.Green;
e.Row.BackColor = Color.Red;
There are two issues with the above approach:
(1) Since we are adding data to GridView by setting DataSource = DataTable and then binding the datatable, I am not sure if that will trigger the above RowDataBound event.
(2) And, since the column structure is not fixed due to different functions using same GridView with different column structure each time, in order to get the Column reference we need to first get reference of the function which is creating the GridView.
Hope this is clear. If not, please feel free to ask for more explaination or any other input from my side.