I am working with ASP.NET and VB.NET in code behind. My question is this:
I have a grid view (Called gvSecondLevel) that is loaded based on query A. (It works fine) The grid view can have anywhere from 1 to X number of rows. There is a Command Button for every row in column zero of gvSecondLevel that when clicked will display another grid view (Called gvThirdLevel) which will display 1 to X number of rows for the line number in gvSecondLevel.
In the gvThirdLEvel there is column called OpComplete, it is either 0 (No) or 255 (Yes). So lets say that gvSecondLevel has 2 lines. For Line 1 there are three lines in the gvThirdLevel, and for gvSecondLevel line 2 there are 4 lines in gvThirdLevel.
Now assume that for gvSecondLevel Line 1 that all OpComplete steps (In gvThirdLEvel) are 255 or Complete.
But for gvSecondLevel Line 2 lets say that the third line (of the four lines) of gvThirdLevel has an OpComplete step that is a 0 but lines 1,2, & 4 are all complete or 255.
What I need to do is have line 2 in gvSecondLevel highlighted because of the third line in gvThirdLevel OpComplete being 0. The kicker is that the gvThirdLevel is not visible UNTIL the user has clicked a line number in gvSecondLevel.
So in essence I need to some how look at all the lines that would be retrieved by the gvThidLevel query for each line in gvSecondlevel and highlight it so that a user knows that a particular line has a problem.
Right now the gvSecondLevel loads but no lines are highlighted. Can anyone point in a direction so that I can try and learn how to do this? Or if by some miracle someone has already had to do this and can share some code that also would work so I can see how it is done.
Update
gvSecondLvl
____________________________________________________________________________
| |Line # | Part Description | PCS | Weight | Sq Foot | Comments |
____________________________________________________________________________
|[cmdButton]| 1 | Part blah blah | 100 | 1,200 | 254 | |
____________________________________________________________________________
|[cmdButton]| 2 | Part blah blah 2 | 50 | 1,500 | 125 | |
____________________________________________________________________________
This loads fine. When someone clicks the cmdButton for a specific line number the gvThirdLvl is Displayed, lets say line 2
gvThirdLvl
___________________________________________________________________________
| Step Comp | Assembly | OP # | WC Code | Due Date | Qty | Qty Completed |
___________________________________________________________________________
| Yes | 0 | 100 | MTLH | 6/12/2017 | 25 | 25 |
___________________________________________________________________________
| No | 0 | 110 | PC | 6/14/2017 | 100 | 0 |
___________________________________________________________________________
Remember that the gvThirdLvlv will not be displayed until the line 2 command button in gvSecondLvl is clicked. But when gvSecondLvl loads I need (in this case) line 2 to be highlighted before any line numbers is clicked. That way the users can see that line 2 (in this case) is the reason that this order is on the report.
If you are populating the rows when you click the button you can set the row background color on the data bind event. Then if the row that is being bound matches your criteria you can highlight it.
Private Sub GridView_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView.RowDataBound, additionalGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If CType(e.Row.FindControl("Line_1"), TextBox).Text = "0" Then
e.Row.BackColor = Color.Red
End If
End If
End Function
This is how I finally managed to get it work.
For i As Integer = 0 To gvDetailSecondLevel.Rows.Count - 1
'If gvDetailSecondLevel.Rows(i).Cells(1).Text.ToString > "0" Then
Dim jNumber As String = lblSONum.Text
Dim lNumber As String = gvDetailSecondLevel.Rows(i).Cells(1).Text.ToString
Dim soNumber As String = jNumber & "." & lNumber
Using conn As New SqlConnection(myConnection2)
conn.Open()
Using sqlCmd As New SqlCommand
sqlCmd.CommandText = ("Select jo.OpComplete From JobOper jo Where jo.JobNum = #JobNum")
sqlCmd.Parameters.AddWithValue("#JobNum", soNumber)
sqlCmd.Connection = conn
Using sqlDa As New SqlDataAdapter(sqlCmd)
Using sqlDT As New DataTable()
sqlDa.Fill(sqlDT)
For Each row As DataRow In sqlDT.Rows
If row.Item(0) = "0" Then
gvDetailSecondLevel.Rows(i).BackColor = Color.Yellow
gvDetailSecondLevel.Rows(i).ForeColor = Color.Red
End If
Next
End Using
End Using
End Using
conn.Close()
End Using
Next
This code is in the gvSecondLvlv DataBound.
Related
Given a dynamic field, say, milestones, it has value like: {"ta": 1655859586546, "tb": 1655859586646},
How do I print a table with columns like "ta", "tb" etc, with the single row as unixtime_milliseconds_todatetime(tolong(taValue)), unixtime_milliseconds_todatetime(tolong(tbValue)) etc.
I figured that I'll need to write a function that I can call, so I created this:-
let f = view(a:string ){
unixtime_milliseconds_todatetime(tolong(a))
};
I can use this function with a normal column as:- project f(columnName).
However, in this case, its a dynamic field, and the number of items in the list is large, so I do not want to enter the fields manually. This is what I have so far.
log_table
| take 1
| evaluate bag_unpack(milestones, "m_") // This gives me fields as columns
// | project-keep m_* // This would work, if I just wanted the value, however, I want `view(columnValue)
| project-keep f(m_*) // This of course doesn't work, but explains the idea.
Based on the mv-apply operator
// Generate data sample. Not part of the solution.
let log_table = materialize(range record_id from 1 to 10 step 1 | mv-apply range(1, 1 + rand(5), 1) on (summarize milestones = make_bag(pack_dictionary(strcat("t", make_string(to_utf8("a")[0] + toint(rand(26)))), 1600000000000 + rand(60000000000)))));
// Solution Starts here.
log_table
| mv-apply kv = milestones on
(
extend k = tostring(bag_keys(kv)[0])
| extend v = unixtime_milliseconds_todatetime(tolong(kv[k]))
| summarize milestones = make_bag(pack_dictionary(k, v))
)
| evaluate bag_unpack(milestones)
record_id
ta
tb
tc
td
te
tf
tg
th
ti
tk
tl
tm
to
tp
tr
tt
tu
tw
tx
tz
1
2021-07-06T20:24:47.767Z
2
2021-05-09T07:21:08.551Z
2022-07-28T20:57:16.025Z
2022-07-28T14:21:33.656Z
2020-11-09T00:54:39.71Z
2020-12-22T00:30:13.463Z
3
2021-12-07T11:07:39.204Z
2022-05-16T04:33:50.002Z
2021-10-20T12:19:27.222Z
4
2022-01-31T23:24:07.305Z
2021-01-20T17:38:53.21Z
5
2022-04-27T22:41:15.643Z
7
2022-01-22T08:30:08.995Z
2021-09-30T08:58:46.47Z
8
2022-03-14T13:41:10.968Z
2022-03-26T10:45:19.56Z
2022-08-06T16:50:37.003Z
10
2021-03-03T11:02:02.217Z
2021-02-28T09:52:24.327Z
2021-04-09T07:08:06.985Z
2020-12-28T20:18:04.973Z
9
2022-02-17T04:55:35.468Z
6
2022-08-02T14:44:15.414Z
2021-03-24T10:22:36.138Z
2020-12-17T01:14:40.652Z
2022-01-30T12:45:54.28Z
2022-03-31T02:29:43.114Z
Fiddle
I have datatable(dtblCostCategory) which has the following values which i use it in the dropdown. And i have saved some data after selecting the value from the dropdown. When i load the same page again the selected value is not being shown instead the first values is shown in dropdown.
dsOtherDetails
CostCategory | typeId | itemCount
----------------------------------------
Softwaré | 3 | 15
dtblCostCategory
CostCategory | typeId
----------------------------
Electronics | 1
Groceries | 2
Softwaré | 3
cboCategory.DataSource = dtblCostCategory
cboCategory.DataTextField = dtblCostCategory.Columns(1).ToString
cboCategory.DataValueField = dtblCostCategory.Columns(0).ToString
cboCategory.DataBind()
Dim lstItem As New ListItem
lstItem.Text = Server.HtmlEncode(Trim(CStr(dsOthersDetails.Tables(0).Rows(0).Item("CostCategory"))))
lstItem.Value = Server.HtmlEncode(CStr(dsOthersDetails.Tables(0).Rows(0).Item("typeId")))
cboCategory.SelectedIndex = cboCategory.Items.IndexOf(lstItem)
In the above code I have used indexOf to get the selected index by comparing the values from two tables. As there is accent in category (Softwaré) the indexOf is not working properly. Is there way where I can get selected index ignoring the accents so that the drop down will have correct selected value.
Try with FindByValue()
cboCategory.SelectedIndex = cboCategory.Items.IndexOf(cboCategory.Items.FindByValue(lstItem.Value));
I want to convert database data into JSON, but what i get by using code from this site using JavaScriptSerializer is like this
[{"Yes":6,"No":1,"Maybe":4}].
I have database table with three column named as Yes, No and Maybe, but I want a JSON format like:
[{"name":"Yes","data":6},{"name":"No","data":2},{"name":"Maybe","data":3}].
Means how to convert it in key:value pair in VB?
My code is :
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object)
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
Next
rows.Add(row)
Next
json_data = serializer.Serialize(rows)
just change to
For Each col As DataColumn In dt.Columns
row.Add("name", col.ColumnName)
row.Add("data", dr(col))
The problem is not in the code. The problem is that the database schema is bad to begin with.
Bad:
+---------+--------+-----------+
| Yes | No | Maybe |
+---------+--------+-----------+
| 6 | 2 | 4 |
+---------+--------+-----------+
Good:
+---------+--------+
| Name | Data |
+---------+--------+
| Yes | 6 |
+---------+--------+
| No | 2 |
+---------+--------+
| Maybe | 4 |
+---------+--------+
EDIT
#Downvoter: suppose that you want to add a new property "Perhaps" later on.
+---------+--------+
| Name | Data |
+---------+--------+
| Yes | 6 |
+---------+--------+
| No | 2 |
+---------+--------+
| Maybe | 4 |
+---------+--------+
| Perhaps | 9 |
+---------+--------+
How would you go about doing this in the original table?
You probably guessed it: by changing the database structure to fit the business model.
I have a spreadsheet where dates are being recorded in regards to individuals, with additional data, as such:
Tom | xyz | 5/2/2012
Dick | foo | 5/2/2012
Tom | bar | 6/1/2012
On another sheet there is a line in which I want to be able to put in the name, such as Tom, and retrieve on the following cell through a formula the data for the LAST (most recent by date) entry in the first sheet. So the first sheet is a log, and the second sheet displays the most recent one. In the following example, the first cell is entered and the remaining are formulas displaying data from the first sheet:
Tom | bar | 6/1/2012
and so on, showing the latest dated entry in the log.
I'm stumped, any ideas?
If you only need to do a single lookup, you can do that by adding two new columns in your log sheet:
Sheet1
| A | B | C | D | E | F
1 | Tom | xyz | 6/2/2012 | | * | *
2 | Dick | foo | 5/2/2012 | | * | *
3 | Tom | bar | 6/1/2012 | | * | *
Sheet2
| A | B | C
1 | Tom | =Sheet1.E1 | =Sheet1.F1
*(E1) = =IF(AND($A1=Sheet2.$A$1;E2=0);B1;E2)
(i.e. paste the formula above in E1, then copy/paste it in the other cells with *)
Explanation: if A is not what you're looking for, go for the next; if it is, but there is a non-empty next, go for the next; otherwise, get it. This way you're selecting the last one corresponding to your search. I'm assuming you want the last entry, not "the one with the most recent date", since that's what you asked in your example. If I interpreted your question wrong, please update it and I can try to provide a better answer.
Update: If the log dates can be out of order, here's how you get the last entry:
*(F1) = =IF(AND($A1=Sheet2.$A$1;C1>=F2);C1;F2)
*(E1) = =IF(C1=F1;B1;E2)
Here I just replaced the test F2=0 (select next if non-empty) for C1>=F2 (select next if more recent) and, for the other column, select next if the first test also did so.
Disclaimer: I'm very inexperienced with spreadsheets, the solution above is ugly but gets the job done. For instance, if you wanted a 2nd row in Sheet2 to do another lookup, you'd need to add two more columns to Sheet1, etc.
+----------+------------+------+------+--------------+---------+---------+
| | SUBJ | MIN | MAX | RESULT | STATUS | PERCENT |
| +------------+------+------+--------------+---------+---------+
| | Subj1 | 35 | 100 | 13 | FAIL | 13.00% |
|EXAM NAME | Subj2 | 35 | 100 | 63 | PASS | 63.00% |
| | Subj3 | 35 | 100 | 35 | PASS | 35.00% |
| +------------+------+------+--------------+---------+---------+
| | Total | 105 | 300 | 111 | PASS | 37.00% |
+----------+------------+------+------+--------------+---------+---------+
This is my report viewer report format.The SubTotal row counts the
total of all the above column.Every thing is fine. But in the status
column its showing Pass. I want it to show fail if there is single
fail in the status column. I am generating Status if Result < Min then
it is fail or else it is pass. Now how to change the SubTotal row
below depending upon the condition. And is there any way to show the
Subtotal row directly from database. Any suggestion.
The easiest way to do this would be to use custom code (right-click non-display area of report, choose Properties and click the Code tab) - calculate the pass/fail score in the detail, display it in the group footer and reset it in the group header:
Dim PassFail As String
// Reset Pass or Fail status in group header
Public Function ResetAndDisplayStatusTitle() AS String
PassFail = "PASS" // Initialise status to pass
ResetAndDisplayStatusTitle = "Status"
End Function
// Calculate pass/fail on each detail row and remember any fails
Public Function CalculatePassFail() As String
Dim ThisResult As String
// Calculate whether this result is pass or fail
If Fields!Result.Value < Fields!Min.Value Then
ThisResult = "FAIL"
Else
ThisResult ="PASS"
End If
// Remember any failure as overall failure
If ThisResult = "FAIL" Then PassFail = "FAIL"
CalculatePassFail = ThisResult
End Function
Then you tie in the custom code to your cells in your table as follows:
In the value for the status column in your group header you put:
=Code.ResetAndDisplayStatusTitle()
In the value for the status column in the detail row you put:
=Code.CalculatePassFail()
In the value for the status column in the group footer you put:
=Code.PassFail
With respect to getting the subtotal row from the database directly from the database, there are a couple of ways depending on what result you are after.
Join the detail row to a subtotalling row in your SQL (so that the subtotal fields appear on every row in the dataset) and use those fields.
Again, use custom code (but this is probably overly complicated for subtotalling)
However, these tricks are only for strange circumstances and in general the normal out-of-the-box subtotalling can be tweaked to give the result you are after. If there is something specific you want to know, it is probably best to explain the problem in a separate question so that issue can be dealt with individually.