highlight gridview cell by header and row values - asp.net

I have a gridview and I was able to highlight a cell based on field name and criteria of cell in that column. Now I want to do the same thing but also consider the row value from the second column as well. Example below
Gender | Part Number | Small | Medium | Large
Men | C-888-TVN | 5 | 6 | 9
Men | C-777-TV4 | 7 | 7 | 8
So if I want to highlight the '7' in the C-777-TV4 row and under the Medium size how would I go about doing both criteria. This is not based on a number value criteria just the name of the header "Medium" and string value in the part number row "C-777-TV4".
Here is the new code that i'm getting an out of range error:
Protected Sub gridStock_HtmlRowPrepared(sender As Object, e As ASPxGridViewTableRowEventArgs) Handles gridStock.HtmlRowPrepared
If e.RowType <> GridViewRowType.Data Then
Return
End If
Dim name As String = e.GetValue("CorePN").ToString()
If name = "777-M-MBL" Then
e.Row.Cells(10).BackColor = System.Drawing.Color.Red
End If
End Sub
Getting the error at e.Row.Cells(10).Backcolor

I need to see more code of yours. Here is what I thought:
If row.Cell(1).Text = "C-777-TV4" Then
e.Row.Cells(5).BackColor = System.Drawing.Color.Cyan
End If

Related

SQL to find next greater records for each element

I've got a table defined like this:
CREATE TABLE event (t REAL, event TEXT, value);
For each record in the table which have event='type' and value='G' there will be two corresponding records with event='Z' - one with value=1 and one with value=0. Here is an example:
t | event | value
1624838448.123 | type | G
1624838448.123 | Z | 1
1624839543.215 | Z | 0
Note that there could be other event='Z' records that don't have corresponding type='G' records. I'm trying to write a query to find all the event='G' records that do have a corresponding type='G' record to use as the bounds for an additional query (or join?).
Note: The t value for the "type" event and the Z event where value=1 will always be the same.
So for instance if the table looked like this:
t | event | value
1624838448.123 | type | G
1624838448.123 | Z | 1
1624839543.215 | Z | 0
1624839555.555 | type | H
1624838555.555 | Z | 1
1624839602.487 | Z | 0
1624839999.385 | type | G
1624839999.385 | Z | 1
1624840141.006 | Z | 0
Then I want the results of the query to return this:
t1 | t2
1624838448.123 | 1624839543.215
1624839999.385 | 1624840141.006
From your comment:
There are always three records (ignoring any other events in between)
in chronological order: the "type" event, the first "Z" record with
the same timestamp, and the second "Z" record with a later timestamp
So, there is no need to return t1 separately since it is equal to t in the row where event = 'type' and value = 'G'.
For t2 you can use conditional aggregation with MIN() window function:
SELECT t1, t2
FROM (
SELECT t AS t1, event, value
MIN(CASE WHEN event = 'Z' AND value = '0' THEN t END) OVER (ORDER BY t ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING) t2
FROM Event
)
WHERE event = 'type' AND value = 'G'
See the demo.
I found a solution using the RANK() function. With this I get an intermediate table which has the same rank for both the "type" and first "Z" record, since they have the same timestamp, and a rank two greater for the second "Z" record. I use WITH so I can self join repeatedly without having to specify the same query over and over. I first join the "type" and first "Z" row by requiring that the type of two second record be greater than that of the first (so I only get the type:Z combination and not type:type, Z:type, or Z:Z). Then I self join again to get the rank-2 row which picks up the second Z record. Overall, the query looks like this:
WITH Seq(t,event,A,I)
AS
(
SELECT t, event, value,
RANK() OVER (ORDER BY t) I
FROM Event e1
WHERE (e1.event='type' OR e1.event='Z')
)
SELECT s2.t,s3.t
FROM Seq s1
INNER JOIN Seq s2 ON s1.I = s2.I AND s1.event < s2.event
INNER JOIN Seq s3 ON s1.I = s3.I-2
WHERE s1.value='G';

rdlc reporting don't show values when groep row exists

I have the following table in my rdlc report
testSubject | (settingUnit) | (BrochureValue) | (TestMethod) - Group 1
TestSetting | SettingUnit | BrochureValue | TestMethod - Group 2
When there is an testSetting in testSubject i want the () values not displayed in the table. Is this possible in RDLC?
You can use expression to show hide value conditionally in each column:
= IIF(Fields!testSubject.Value = "testSetting","",Fields!settingUnit.Value)
You can completely hide row also. for that you have to use expression in row visibility.
= IIF(Fields!testSubject.Value = "testSetting",false,true)

read and modify/update cell in datatable

Scenario
I want to calculate and rank the suitability of healthcare workers for a particular patients, by comparing parameters such as race, religion, gender, spoken language, etc.
HealthcareWorker table
----------------------
ID (int)
name (varchar)
race (varchar)
religion (varchar)
gender (varchar)
german (bit)
french (bit)
english (bit)
Patient table
-------------
ID (int)
name (varchar)
race (varchar)
religion (varchar)
gender (varchar)
german (bit)
french (bit)
english (bit)
Webpage Layout
On page1.aspx there will be a gridview table showing the details of all Patients.
User will then select a Patient and be directed to page2.aspx
On page2.aspx there will a table showing the details of each Healthcare Worker and his suitability with the selected patient in the form of a score. there will also be checkboxes inside the table in order to assign more than one Healthcare Worker to the selected Patient.
page2.aspx
| ID | name | religion | gender | german | french | english | score | |
|----+-------+----------+---------+----------+---------+----------+--------+----------|
| 4 | mary | | f | 1 | 0 | 1 | 132 | checkbox |
| 2 | john | | m | 0 | 1 | 1 | 125 | checkbox |
| 3 | tim | | m | 1 | 0 | 1 | 98 | checkbox |
| 1 | jane | | f | 1 | 1 | 0 | 55 | checkbox |
the computation of the score will be something like this:
if patient.race = healthcareworker.race then healthcarework.score +10
if patient.religion = healthcareworker.religion then healthcarework.score +10
if at least one of patient's language match with healthcareworker's language then healthcarework.score +10
code:
Dim strCon As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
Dim con As New SqlConnection(strCon)
Dim query As String = "select *, CAST ( 0 as int ) score from HealthcareWorker;"
Dim cmd As SqlCommand = New SqlCommand(query, con)
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim dt As DataTable = New DataTable()
dt.Load(dr)
'code to read cell
'code to compare and compute
'code to update the score in each row
GridView1.DataSource = dt
GridView1.DataBind()
con.Close()
How do I read and modify the cells in the datatable?
I want read and compare the data from some cells in each row and then update the score value.
I need to update the score for each row so I am going to need a loop but I do not know the number of rows that will be loaded into the datatable before hand.
How do I get the number of rows in the datatable?
edit/update: reworked the entire question to provide (a lot) more background information
The last question is answered easily:
I need to update the score for each row so I am going to need a loop
but I do not know the number of rows that will be loaded into the
datatable before hand. How do I get the number of rows in the
datatable?
You just have to use the Rows.Count property:
Dim rowCount As Int32 = tblPatient.Rows.Count ' tblPatient => DataTable '
If you want to loop all rows you can use a foreach:
For Each row As DataRow In tblPatient.Rows
' ... '
Next
or a for-loop:
For i As Int32 = 0 To tblPatient.Rows.Count - 1
Dim row As DataRow = tblPatient.Rows(i)
' ... '
Next
To update the rows you can use the SetField extension method which also support nullable-types:
For Each row As DataRow In tblPatient.Rows
Dim id As Int32 = row.Field(Of Int32)("ID")
Dim race As String = row.Field(Of String)("Race")
row.SetField("Score", CalculateScore(row))
Next
Sorry that i cannot provide you the correct calculation but it's still not clear how you want to calculate it since you haven't provided the source of the Score(theres no column). But it might give you an idea anyway.

selecting a row based on a number of column values in SQLite

I have a table with this structure:
id | IDs | Name | Type
1 | 10 | A | 1
2 | 11 | B | 1
3 | 12 | C | 2
4 | 13 | D | 3
except id nothing else is a FOREIGN or PRIMARY KEY. I want to select a row based on it's column values that are not PRIMARY KEY. I have tried the following syntax but it yields no results.
SELECT * FROM MyTable WHERE Name = 'A', Type = 1;
what am I doing wrong? What is exactly returned by a SELECT statement? I'm totally new to Data Base and I'm currently experimenting and trying to learn it. so far my search has not yield any results regarding this case.
Use and to add multiple conditions to your query
SELECT *
FROM MyTable
WHERE Name = 'A'
AND Type = 1;

How to select n rows using IDataReader

[ASP .Net - Microsoft Visual Web Developer 2010]
Hi all,
I've problem with this code:
With MenuNavCatDataSource
Dim xReader As Data.IDataReader = .Select(DataSourceSelectArguments.Empty)
If xReader.Read Then
MenuNavCat1.Text = xReader.Item("MenuCategoryName")
MenuNavCat2.Text = xReader.Item("MenuCategoryName")
MenuNavCat3.Text = xReader.Item("MenuCategoryName")
MenuNavCat4.Text = xReader.Item("MenuCategoryName")
MenuNavCat5.Text = xReader.Item("MenuCategoryName")
End If
End With
I've 5 label and I want to parse the content of the label from the database. The database contains menus ordered from 1 to 5. And I want to show it on:
- 'MenuNavCat1' label, menu with order number 1 on database,
- 'MenuNavCat2' label, menu with order number 2 on database, and so on...
How to add where statement to the code, just like 'WHERE OrderNo = 1', and so on..?
Need your help guys..
Thank you so much.
EDIT
Here is the database:
Table MenuNavCategory
| Column Name | Data Type |
|-----------------------------|
| MenuNavCatID | int |
| CategoryName | varchar(20) |
| OrderNumber | int |
|-----------------------------|
And there is some value inserted to the table.
I want to show the 'CategoryName' onto some label.
For example:
lblCat1 | lblCat2 | lblCat3 | lblCat4
Then, using that xReader.Read, store the value on the database onto that label based on the OrderNumber...
The DataReader only reads one row of data at a time. If you have 5 labels then you should have 5 rows in your database. Then you iterate through each row using the DataReader and assign the labels:
With MenuNavCatDataSource
Dim xReader As Data.IDataReader = .Select(DataSourceSelectArguments.Empty)
'i is just a counter to keep track of what row we are on.
Dim i as integer = 1
If xReader.Read Then
Select Case i
Case 1 'First Row from DB.
MenuNavCat1.Text = xReader.Item("MenuCategoryName")
Case 2 'Second Row from DB... etc.
MenuNavCat2.Text = xReader.Item("MenuCategoryName")
Case 3
MenuNavCat3.Text = xReader.Item("MenuCategoryName")
Case 4
MenuNavCat4.Text = xReader.Item("MenuCategoryName")
Case 5
MenuNavCat5.Text = xReader.Item("MenuCategoryName")
x+=1
End If
End With
The above is just an example to try and explain how the DataReader works. I'd find another way to actually code it as the above relies on the rows in the database being in the correct order and is pretty ugly.

Resources