I have a gridview and I need to have counter in that. I mean, I need to have a column that shows the rows number in sort. For example:
|Num|Name |
-----------
| 1 |Alex |
| 2 |Alice|
| 3 |Cat |
Please let me know if you have any idea.
Just use the following code in a label:
<asp:TemplateField>
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
Related
I'm using a FormView Repeater to display my data in a table. However, I want to group the same data together. I have total 4 categories. Ford, Nissan, Toyota, and Volvo. The data row for each brand of car is different. How to group it and make it show only once?
<asp:Repeater runat="server" DataSource='<%# Container.DataSource %>'>
<ItemTemplate>
<tr>
<td align="right">Ford</td>
<td align="left"><%# Eval("Carcode")%></td>
<td align="left"><%# Eval("PlateNum")%></td>
<td align="left"><%# Eval("StoreName")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
My results from the Data Table:
Car_Name Car_Code Plate_Number Store_Name
Ford 1234 abc123 storeA
Ford 1121 abc111 storeB
Ford 2311 aaa111 storeC
.....................................
Expected Results:
Car_Name Car_Code Plate_Number Store_Name
Ford 1234 abc123 storeA
1121 abc111 storeB
2311 aaa111 storeC
Nissan 1234 abc123 storeA
1121 abc111 storeB
2311 aaa111 storeC
Change your markup around the company name like:
<td align="right">
<asp:Label id="lblName" runat="server" Text='<%# Eval("CompanyName") %>' />
</td>
Create a private variable
private _lastCompany As String = ""
In the event handler
Public Sub ItemDatabound(e As RepeaterItemEventArgs) ..
Dim data As ClassType = CType(e.Item.DataItem, ClassType)
If (data.CompanyName = _lastCompany) Then
e.Item.FindControl("lblName").Visible = False
End If
_lastCompany = data.CompanyName
End Sub
You can use the ItemDataBound event to get the value of the row, and compare to a variable that has the previous item. Hide the control anytime the previous row matches the current row.
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.
Is there a way to input a newline into a table cell? For example, say I have a table like this:
+==========+==========+==========+
+ Header 1 + Header 2 + Header 3 +
+==========+==========+==========+
+ Item 1 + + +
+ Item 2 + + +
+----------+----------+----------+
I want the above to create a table with two rows, three columns, and the second row, first column to display Item 1 and Item 2 on separate lines.
I have tried the line blocks syntax |, but it doesn't work inside a table cell. I can use list syntax, but I don't want bullet points to appear.
First of all I think your table syntax is incorrect, should it not be:
+----------+----------+----------+
| Header 1 | Header 2 | Header 3 |
+==========+==========+==========+
| Item 1 | | |
| Item 2 | | |
+----------+----------+----------+
Note that the top row is made up of hyphens, not equal signs, and the rows are separated by pipes, |, not plus signs.
Now with this table, the line block syntax:
+----------+----------+----------+
| Header 1 | Header 2 | Header 3 |
+==========+==========+==========+
| | Item 1 | | |
| | Item 2 | | |
+----------+----------+----------+
seems to work: testing with Pandoc the bottom left cell gets transformed into the following HTML:
<td align="left">Item 1<br />Item 2</td>
Note the line break <br /> in between Item 1 and Item 2.
You can also leave a gap between the lines like this
+----------+----------+----------+
| Header 1 | Header 2 | Header 3 |
+==========+==========+==========+
| Item 1 | | |
| | | |
| Item 2 | | |
+----------+----------+----------+
This method tends to be friendlier with editors so they dont think you have accidentally added an extra pipe
I use the following syntax to create tables including multiline cells with sphinx:
.. list-table::
* - **HEADER1**
- **HEADER2**
- **HEADER3**
* - TEXT 1
- | MULTILINE
| TEXT
- | MULTILINE
| TEXT 2
I use line blocks with beginning | to preserve the line-breaks.
Is there anyway to refer a table in RestructuredText? something like see table `referencetable`_
(I saw some workarounds for referencing figures. couldn't find a way to refer a table though .. )
Thanks!
You can simply define a hyperlink target.
Here is table-1_.
.. _table-1:
+------------+------------+-----------+
| Header 1 | Header 2 | Header 3 |
+============+============+===========+
| body row 1 | column 2 | column 3 |
+------------+------------+-----------+
| body row 2 | Cells may span columns.|
+------------+------------+-----------+
| body row 3 | Cells may | - Cells |
+------------+ span rows. | - contain |
| body row 4 | | - blocks. |
+------------+------------+-----------+
I have a database with students, and a weekly figure based upon them. I would like to create a gridview, with a dynamically expanding set of columns and rows, whereby Rows are weeks 1,2,...,n and columns represent each student, or vice versa.
Reviews data table looks like this:
======================================
| Stu# | Week# | Score | Review# |
--------------------------------------
| 123 | 1 | A+ | 832 |
| 123 | 2 | C- | 352 |
. . . . .
. . . . .
. . . . .
| 321 | 12 | B | 992 |
| 321 | 13 | A- | 935 |
======================================
So basically, I would like to pull out a review for
In each of these cells I would like to have a weekly figure based on a review submitted on them, and a link to this review. Much like:
_____________________________
| Week | StudentA | StudentB |
| No. | (123) | (321) |
-------------------------------
| 1 | A+ | B- |
| 2 | ... | ... |
. . . .
. . . .
. . . .
| 13 | A+ | B- |
-------------------------------
I have looked at a few (hundred) similar, yet not identical problems in an attempt to stich something together, but so far have been dumfounded.
It's almost like it would represent an excel spreadsheet with links to specific data entries.
I had a go at creating a List, within a list whereby but that became too muddled.
Then I tried doing it with a DataTable, whereby the columns and rows were created at the start, but didnt know how to DataBind() the table inclusive of hyperlinks (in the form of URLParameters to an aspx page of course).
Ok, I've gone ahead and generated a DataTable dynamically and bound it to my GridView, which workd perfectly fine for plaintext results, but I would like to create hyperlinks for each element (ie, the A+) so a particular mark can be read, with comments etc.
I tried adding an tag, but thanks to ASP.net's code-injection protection, it didnt quite work. so basically I had:
HyperLink thisScore = new HyperLink();
thisScore.NavigateUrl=string.Format("<a href='studentMarks.aspx?groupID={0}&week={1}&studentID={2}'>{3}</a>", groupID, week, reader["student_ID"], reader[studentScoreLocation]);
newRow[studentName] = thisScore;
Followed by an attempt to use a HyperLink objet (to no avail)
HyperLink thisScore = new HyperLink();
thisScore.NavigateUrl=string.Format("studentMarks.aspx?groupID={0}&week={1}&studentID={2}", groupID, week, reader["student_ID"]);
thisScore.Text = reader[studentScoreLocation].ToString();
newRow[studentName] = thisScore;
What would be the best way to get around this?