Restricting number of rows in Datalist - asp.net

In my asp.net I am using Datalist in that I want to limit row count and want the sort to be in vertical. Let me know how to do this.
Ex: I want my list to be like this
1 4
2 5
3 6

for your first issue, restricting to number of rows is, just pass the required data to datalist and for vertical , use this property RepeatDirection="Vertical"

Related

I have ASP.NET GridView in my web app and would like to bind 3 columns with values based on one column

I have ASP.NET GridView in my web app and would like to bind 3 columns with values based on one column. I am providing example below, is it possible to implement into GridView?
My Gridview fields are
Name|Score1|Score2|Score3
I will display the name but how to fill the score fields based on name.there are 3 scores corresponding to each name,that we taken from the same table with a single score field.the 3 scores are provided by 3 different persons.Also i want to display the corresponding score providers name in the header portion of the gridview.
ie,
Name|Ram Score1|Raju Score2|Mohan Score3
How can i do this...
Plz provide the query to do this
Consider to rather calculate the scoring fields in database. Create a stored procedure and bind it to the grid view.

Show/hide groups of rows without subtotalling in SSRS 2005?

I have a matrix report in SSRS 2005, and the rows have certain sections. Imagine along the left a series of
1 $100
2 $400
3 $150
4 $650
5 $500
6 $400
7 $900
And I want some rows to be able to be hidden. For example, row 7 are totals of row 5 and 6, so I'd want to +/- next to row 7 that will show/hide rows 5 and 6. (Note that I don't calculate these totals, they were done by an accountant and it is important that I use the values in the database and don't calculate the totals myself.)
Now I have this "parent/child" relationship in the database, and I could add that as a group on the row
4 1 $100
4 2 $400
4 3 $150
- 4 4 $650
7 5 $500
7 6 $400
- 7 7 $900
And then I could add the toggle to that first column, BUT I don't want the values to be subtotaled when they are rolled up. I simply want rows 5/6 to disappear and only show row 7. Kind of new to SSRS so any suggestions would be great.
So with one group toggled:
+ 4 4 $650
7 5 $500
7 6 $400
- 7 7 $900
Other gorup toggled:
+ 4 4 $650
+ 7 7 $900
Etc.
4 1 $100
4 2 $400
4 3 $150
- 4 4 $650
+ 7 7 $900
How can I accomplish this such that I am not recalculating the parent rows(rows 4 and 7 in this example)?
If there is a free web control that can accomplish this in ASP.NET I'd be glad to hear about it as well. I have a sinking feeling that I'm going to have to write some AJAX myself to accomplish this. I kind of wondered if there was some hack to embed some javascript into the report that could accomplish this.
Effectively you have two problems:
Report subtotals that come from the database, not calculated
Dynamically hide and expose detail rows
You can do this with a standard table report, as follows:
Report database subtotals
You can do this in plain SQL (D is the Detail table and G is the Group table):
SELECT D.ParentId, D.ChildId,
D.Description as DetailDescription, D.Amount AS DetailAmount,
G.GroupDescription, G.GroupAmount
FROM MyTable D INNER JOIN
(SELECT ChildId AS GroupId, Max(Description) as GroupDescription, MAX(Amount) AS GroupAmount
FROM MyTable
GROUP BY ChildId
WHERE ChildId IN (SELECT DISTINCT ParentId FROM MyTable)) G ON GroupId = D.ParentId
WHERE D.ChildId NOT IN (SELECT DISTINCT ParentId FROM MyTable)
So what we are doing is getting all the rows which aren't subtotals (that is, the rows where the ChildId is not a ParentId) and in the nested select we are also putting the subtotal on every detail line. Now, in the Group on the table, we can simply report the GroupTotal field from our dataset rather than an actual subtotal.
Dynamically hide and expose rows
Create a group in your table. Here is where you report the GroupTotal just as a field, not as a total (although you could MAX or MIN it if you wanted to).
Right-click the detail group and click Edit. On the Visibility tab, check the Visibility can be toggled by another report item checkbox and select the textbox name of the first textbox of the group above. Set the Initial Visibility to either Visible or Hidden as required.
Off the top of my head and untested but you should get the idea.
Edit to explain layout better (Note: SQL above also edited to show descriptions)
I'm working with a table here, not a matrix.
Layout would look like as follows (first column shows what group you are on):
Table Header Parent Id Child Id Description Amount
Group1 Header =Fields!ParentId.Value =Last(Fields!GroupDescription.Value) =Max(Fields!GroupAmount.Value)
Details Group =Fields!ParentId.Value =Fields!ChildId.Value =Fields!DetailDescription.Value =Fields!DetailAmount.Value
Group1 is set to Group on ParentId, only the header is displayed (no footer) and the ParentId Textbox on that group is called ParentIdGroup. Details Group has "Visibility can be toggled by another item" checked and "Report item" is set to ParentIdGroup.
I have mocked up this report now and it works as you describe - what looks like subtotals are actually database fields and the description shows on the group row.
I was able to accomplish this by setting the expression for the data field value to Last, since in my case the subtotals are always the last row of the series of rows. Whenever the rows are expanded, then Last displays the value for each row, since each row is it's own group. And then whenever I collapse using the PatenLineNumber toggle, then the Last shows the value of that parent row, since it appears as the last row in the group.
So my matrix report is something like this:
Amount
ParentLineNumber ChildLineNumber =Last(Fields!Amount.Value)
I am still having a seperate issue, but that is a seperate question.

How can I set item count value per coloumn in DataList ItemTemplate?

I want to set my DataList control to have only 7 items visible in each column after DataBind.
Let's say' if I have 18 items in the data source; DataList should be rendered as 3 colums.
1st column will have first 7 items.
2nd column will have items from 8 to 15
3rd column will have items from 16 to 18
How can I set the item count per column for each itemTemplate?
Take a look onto DataList.RepeatColumns property:
DataList1.RepeatColumns = 3;
DataList1.RepeatDirection = RepeatDirection.Vertical;
It sounds like you're talking about limiting the rows, which you can do in your datasource before you bind.
If you are binding to a DataSet or a DataTable, you can create a DataView and filter the data to a subset of rows choosing the seven that you wish to display.
Or perhaps you're looking to page your data? In that case you'll set your DataList's PageSize to 7. (see this article for more: https://web.archive.org/web/20211020121644/https://www.4guysfromrolla.com/articles/081804-1.aspx)

Looping data with a Repeater

For an example of what I'm attempting to accomplish, see below. I need to loop through a data source, displaying a value from every datarow in its own tablecell. (table is 3 columns wide)
Normally I'd use a modulus in the code behind to determine if a table row should be ended and a new row started. But I swear I recall reading that the Repeater control has this capability built in.
Pseudocode/table:
Header: <table>
<tr><td>Bind("ProductID")</td><td>Bind("ProductID")</td><td>Bind("ProductID")</td></tr>
Footer: </table>
A simple example of the output is:
1 2 3
4 5 6
7 8 9
So what I'm wondering is there a "built in" way to accomplish this, or should I proceed with a mod check in the code behind.
Thanks
Kevin
The Repeater does not have it the ListView however does.
Edit I was actually thinking of the DataList (new name for the "old" ListView") as Canavar mentions, but the new ListView is so flexible I'd bet you can use it as well.
You can use DataList's RepeatColumns property.

Display rows in multiple columns in Asp.net Gridview

By default each row of a Gridview maps to each row in a datatable or dataset attached to its datasource. But what if I want to display these rows in multiple columns. For example if it has 10 rows, 5 rows each should be displayed in 2 columns side by side. Also can I do this with the Infragistics grid. Is this possible?
You can use a DataList control instead. It has a RepeatColumns property that you can define the number of columns you want to display.
In .NET Framework 3.5, there is an even better solution, the ListView control. You can find further information about how to use the ListView control here.
If this is a pure coding exercise, then bind to the RowDataBound event of the Gridview. That way, you can do:
e.Row.Cells(2).Text = e.Row.Cells(1).Text
This would place the text from column 1 in column 2 after it has been pulled from the database. You can also dynamically create columns using a similar method.
Re-reading, I think I misunderstand your problem though.
Can't you just put two identical bound columns one after the other?

Resources