I am searching for the answer for the whole day.
Basically, I have two html tables and a recordset in getrows()
The page is designed so that there are two html tables and I need to generate it, no other choice to re-design the page :(
Here are the html tables. They are horizontally aligned.
table1 table2
row row
row row
row row
and so on...
How can I generate these tables and of course I do not know how many records are in the recordset.
lets assume that there are 3 fields, name, quantity and date. so, there will be two html tables and i get six columns, three of each table. i will not distribute different fields to different tables. so tables are just the same, side by side, with different data on them, not the fields
You can create a "container table" that will have the two side-by-side tables within so that they lay out as you desire. You didn't specify, so I have table 1 with the first half of the data, and table 2 with the second half. (It's a bit easier/more straightforward, but you can do it with only a little extra effort to have row 1 in table 1, row 2 in table 2, row 3 in table 1, row 4 in table 2, etc.)
So, starting from the array of your records obtained via GetRows (arrData in my example below), and assuming your array has them in the order (from left to right) you want them displayed:
Response.Write "<table><tr><td>"
dim intLastRow
intLastRow = ubound(arrData, 2)
dim intBreakPoint
intBreakPoint = fix(intLastRow/2)
dim intSecondStartPoint = intBreakPoint + 1
Response.Write "<table>"
dim i
for i = 0 to intBreakPoint
Response.Write "<tr><td>" & arrData(0, i) & "</td><td>" & arrData(1, i) & "</td><td>" & arrData(2, i) & "</td></tr>"
next
Response.Write "</table>"
if intLastRow > 0 then
Response.Write "<table>"
for i = intSecondStartPoint to intLastRow
Response.Write "<tr><td>" & arrData(0, i) & "</td><td>" & arrData(1, i) & "</td><td>" & arrData(2, i) & "</td></tr>"
next
Response.Write "</table>"
end if
Response.Write "</td></tr></table>"
Related
All I know is ControlListView function: http://www.autoitscript.com/autoit3/docs/functions/ControlListView.htm
and there is an option GetText with two parameters for row and column but there I can't see anything to get the text of column heading, that is the place where user can click by mouse and for example sort by that column etc.
You could try using _GUICtrlListView_GetColumn. This function returns an array with information about the given ListView column.
Local $aCol = _GUICtrlListView_GetColumn($lvwMsgTable, 0)
ConsoleWrite('Title of column 0: ' & $aCol[5] & #LF)
$aCol = _GUICtrlListView_GetColumn($lvwMsgTable, 1)
ConsoleWrite('Title of column 1: ' & $aCol[5] & #LF)
$aCol = _GUICtrlListView_GetColumn($lvwMsgTable, 2)
ConsoleWrite('Title of column 2: ' & $aCol[5] & #LF)
I don't know if this is working with a TListView though.
I have a string which I formatted and then I split it using | character. Then the data between each |I am inserting into a list each with a unique index. Now I am trying to join two elements in that list so that they can be in one index.
Example
`List FruitSalad
fruit.add("Apple")
fruit.add("Orange")
fruit.add("Tomatoes")
fruit.add("bananas")
fruit.add("Cucumber")
TextBox1.Text = fruit(0)
TextBox2.Text = fruit(1)
TextBox3.Text = fruit(3)
Typically Apple would have index(0) and Orange and bananas would have the index(1) and index(2) respectively. The thing is I want to join or merge index(2) with index(1) so that both elements would be merged in one index. e.g. index(1) has Apple and Orange.
How could I write it in terms of assigning it to a TextBox.Text, what would be the correct format for TextBox.Text = fruit(?). I tried fruit.Join(2)(1) and String.Join(result(2)(1).ToArray) but that didn't work. Any suggestions? Regards.
Why not concatenate the two
TextBox1.Text = fruits(1) & " and " & fruits(2)
or
TextBox1.Text = String.Format("{0} and {1}", fruits(1), fruits(2))
I'm trying to add div after a group of 5 rows of data inside Listview.
I came up with using Mod 5 = 0 but I realized the last row is missing if total row count can't divided by 5.
For example, I have 11 rows of data.
"Div" will be added after 5 and 10.
I also need to add "Div" after 11 as well. (div will display details of each group)
So, something like this
1|2|3|4|5
DIV1
6|7|8|9|10
DIV2
11|
Div3(missing)
Here is inline code I have so far
<%# IIf((Container.DisplayIndex + 6) Mod 5 = 0, "<div id='temp" + Math.Floor((Container.DisplayIndex + 6) / 5).ToString + "' style='display:none'></div>", "")%>
How do I add the last div when total # can't be divided by 5?
I have to get the total# of display index somehow...
You can compare it with the ListView.Items.Count property.
This should work:
Dim addDiv = (Container.DisplayIndex Mod 5 = 0) OrElse _
(Container.DisplayIndex + 1 = ListView1.Items.Count)
If you are using paging you should use DataItemIndex instead of DisplayIndex.
Edit: (according to your last comment)
If you need to show the total record count you have to cast the ListView's DataSource to it's correct type(f.e. a DataTable).
Dim tbl as DataTable = DirectCast(ListView1.DataSource, DataTable)
Dim totalCount as Int32 = tbl.Rows.Count
or in one line:
DirectCast(ListView1.DataSource, DataTable).Rows.Count
But this works only on databinding and not on every postback because the DataSource will be disposed at the end of the Page-Lifecycle.
the "+6" makes it look like you're guessing around how the modulo function works :)
try this:
<%# IIf(Container.DisplayIndex Mod 5 = 4 Or Container.DisplayIndex = ListView.Items.Count , "<div id='temp" + (1+Math.Floor(Container.DisplayIndex/5)).ToString + "' style='display:none'></div>", "")%>
so first (index+6)%5 == 0 is the same as index%5 == 4,
second floor((index+6)/5) results in 2 when index=4, this is not what you want.
using 1+floor(index/5) will give you the correct results --- you could even drop the "1+" if you want the index to start from 0.
(p.s. i don't know asp.net, sorry if there's compiler errors)
Please help out newbie.
I am reading mothly sales statistics for last two years from stored procedure, display it on asp.net site and it works just fine.
Problem is with products that are not sold often I need to figure out which months do not have any sales. In that case I need to put zero in table cell and move to next row in dataset.
For...Each does not do the trick in case where there isn't data for every month.
Question is, how to move to next sqlrow and how to test when all rows heve been read?
sqlSelect = "EXECUTE dealer_sales_statistics #productID = '" & strProdID.Value & "'"
Dim sqlConn As New SqlConnection(sqlConnStr)
Dim sqlRow As DataRow
sqlConn.Open()
Dim sqlAdapt As New SqlDataAdapter(sqlSelect,sqlConn)
Dim sqlDataSet As New DataSet()
sqlAdapt.Fill(sqlDataSet, "sales_statistics")
Do Until sqlRow.EOF
If intCounter < 12 Then
' arrMonth contains last 24 months, e.g. "12_2009" to "1_2008"'
' stored procedure can return values for any month between that range'
' amount of returned values (DataSet sqlRows) can vary from 0 to 24'
If arrMonth(intCounter) = sqlRow("month") & "_" & sqlRow("year") Then
strLine_1 &= "<td>" & CInt(sqlRow("qty")) & "</td>"
arrSumma_1 = arrSumma_1 + CInt(sqlRow("qty"))
sqlRow.MoveNext
Else
strLine_1 &= "<td class='cell'>0</td>"
End If
Else
'using intCouter and same code to separate sales in 12 month periods'
If arrMonth(intCounter) = sqlRow("month") & "_" & sqlRow("year") Then
strLine_2 &= "<td>" & CInt(sqlRow("qty")) & "</td>"
arrSumma_2 = arrSumma_2 + CInt(sqlRow("qty"))
sqlRow.MoveNext
Else
strLine_2 &= "<td>0</td>"
End If
End If
intCounter = intCounter + 1
Loop
I think that you are focusing on the wrong area by trying to do this in your code. I can think of a likely solution there but it is really messy. Instead, focus on making sure that the sets returned by the stored proc are complete so you can iterate them without worry about missing months. That is, the stored procedure is probably returning sets made up only of months where there were sales (e.g. due to an inner join) - and you need to change this so it returns all months.
So, instead of posting the VB code, I'd suggest that you post the stored proc to get help in resolving the issue.
As a general guideline, I'd approach this by creating a dummy table with the months of the year listed (along with their month numbers to perform the join). Then, fold that table in with the query using a left outer join to ensure that all months are represented. Also, when selecting the final sales figures, make sure that there are no null values (for months where there were no sales) by using an "IsNull(Val, 0) as Val" to substitute a zero.
Again, this is just general guidance, we'd need to see the actual sproc to really help.
Here is how I did solve this with SQL. I create dynamically temp table that holds last 24 months and another temp table with sales data 0 to 24 months. Maybe this will help somebody with similar problem. (code below is in sql server as stored procedure). Thank you for help Mark!
DECLARE #strTemp_months TABLE
(
sorting INT,
months INT,
years INT
)
DECLARE #mnth INT
SET #mnth = 0
WHILE (#mnth < 24)
BEGIN
INSERT #strTemp_months
SELECT CASE WHEN YEAR(GETDATE()) = YEAR(DATEADD( m , -#mnth , GETDATE())) THEN 1 ELSE 2 END AS sorting,
MONTH(DATEADD( m , -#mnth , GETDATE())), YEAR(DATEADD( m , -#mnth , GETDATE()))
SET #mnth = #mnth + 1
END
DECLARE #productID VARCHAR(12)
SET #productID = '1234567890'
DECLARE #strTemp_statistics TABLE
(
sorting INT,
months INT,
years INT,
productno VARCHAR(35),
salesqty DECIMAL(9,2)
)
INSERT #strTemp_statistics
SELECT CASE WHEN YEAR(transaction_date) = YEAR(GETDATE()) THEN 1 ELSE 2 END AS sorting,
MONTH(transaction_date) AS months, YEAR(transaction_date) AS years, product_number AS productno,
SUM(qty) AS salesqty
FROM sales_events
WHERE product_number = #productID
-- including all transactions from last 24 full months until today
AND transaction_date >= CAST(YEAR(DATEADD( m , -23 , GETDATE())) AS CHAR(4)) + '-' + CAST(MONTH(DATEADD( m , -23 , GETDATE())) AS VARCHAR(2)) + '-01'
GROUP BY MONTH(transaction_date), YEAR(transaction_date), product_number
SELECT m.sorting, m.months, m.years, COALESCE(productno, 'No Sales') AS productno, COALESCE(kpl, 0) AS salesqty
FROM #strTemp_months m LEFT OUTER JOIN #strTemp_statistics s
ON m.months = s.months AND m.years = s.years
ORDER BY 1, 2 DESC
For Each dr As myDAL.UsersRow In data
str.AppendLine(dr.UserName)
Next
In the above code, I also need to include the row index so that it's something like
str.AppendLine(dr.IndexNumber & " " & dr.UserName)
How can I achieve this?
P.S. data is not a DataTable but a generic list of myDAL.UsersRow
If data is a List<myDAL.UsersRow> as you suggest, you can use a "for" loop rather than a "for each" loop:
for i = 0 to data.Count - 1
str.AppendLine(i & " " & data[i].UserName)
next
If, however, you're implying that your "data" list is not in the same order as the original DataTable's rows, you might be able to use the DataRowCollection.IndexOf method to locate the row in the original table:
for each dr as myDAL.UsersRow in data
str.AppendLine(dr.Table.Rows.IndexOf(dr) & " " & dr.UserName)
next
Declare a counter variable before the ForEach loop, and increment it inside it.
Dim counter As Integer = 0
For Each dr As myDAL.UsersRow In data
counter = counter + 1
str.AppendLine(counter.ToString() & " " & dr.UserName)
Next