C# - Get A List Of Distinct Items And Their Count?

Jan 6, 2010

I have an object, that has many properties but the only two to worry about are:

myobject.ID which is an int
myobject.Names which is a HashSet

Then I have a List of those objects that looks something similar to this:

List<myobject>

I use Linq to get a some of the data into a repeater, but I'm not sure how to get the list of Names and how often they show up.

Want to use Linq to avoid having to loop through the data.

As my tags should show, this is an ASP.NET solution using C#.

Some clarification:
Lets say I have just three items in my list:
Item 1 has John, Fred, Jack in its names.
Item 2 has John, Fred, Joe in its names.
Item 3 has John in its names.

I am trying to return the following:
John - 3
Fred - 2
Jack - 1
Joe - 1

Also, as a note I am familiar with having to write my own comparer for my object, I'm just missing the 'how to' for the overall solution in my thoughts.

View 2 Replies


Similar Messages:

ADO.NET :: How To Select Distinct With Count

Nov 3, 2010

This is something I can easily do in SQL, but I'm pretty new to LINQ and haven't been able to find an answer online.

I need a LINQ query that returns two values; the first a distinct value and the second the count of the first value. This is filtered by a parameter. Here is my table:

[code]....

View 2 Replies

SQL Server :: How To Use Distinct On A Single Column From A List Of Columns

Jan 21, 2011

I would like to know if there is a way that I can use DISTINCT on one column's values but need to show other columns where the value of the DISTINCT column is equal to another table's column

View 7 Replies

ADO.NET :: Fetching Only Distinct Values Of Particular Column To Assign To Dropdown List?

Nov 19, 2010

As I kept my fetched datatables into session and accessing it on another page there I am

wroking on datatable to fetch only distinct values of particular column to assign to dropdown list.

View 1 Replies

SQL Server :: Query To Return Conditional Counts Both Distinct And Non Distinct?

Sep 30, 2010

I have the following table structure:

[code]....

The following query returns the default recordset:

[code]....

View 4 Replies

How To Get The Count Of Items From 2 Dates

Sep 15, 2010

How to get the count of items from 2 dates, which has been modified in last 30 days.

[Code]....

How to get the count of items, which have been modified in last 30 days.

View 5 Replies

SQL Server :: Select Number Of Items With Distinct Brand For Each Brand?

Feb 4, 2011

I have a page where I'm displaying all the different brand that I company stocks

For each distinct brand I need to display a count of the number of items with that particular brand

e.g.

brand name
number of products with that brand
brand name 2
number of products with that brand
brand name 3
number of products with that brand

View 2 Replies

Select Distinct And Include Non-distinct Columns?

Apr 20, 2010

I would like to select a distinct query based on three fields and display the rest of the fields. For example,

I have firstname, lastname, address, city, state and zip, but I only want to use the distinct on these fields first and last name. However when i use the distinct function I get a distinct on all the selected rows. I just want to distinct firstname and lastname and display the other fields. for example,

Mary Smith New York
Mary Smithy New York
Mary Smith Maine

I would like the result to be:

Mary Smith New York
Mary Smithy New York

I don't care about Mary Smith Maine, because i am only using the distinct for "Mary Smith" firstname and last name and showing the city.

View 15 Replies

JQuery :: Cannot Count Number Of Checked Items

Sep 1, 2010

Using Microsoft built-in jquery files, when counting numbers of checked checkbox, the jquery-1.4.2.min.js cannot count the correct result ,however, the version jquery-1.3.2.min.js gives out the correct one, why?

$("#check").click(function () {
var nameSports = new Array();
var i = 0;
$('input[name=selector]:checked').each(function () {
nameSports[i] = jQuery(this).val();
i += 1;
});
if (loopCounter != 0) {
alert(i);
}
});
<input type="checkbox" value="1" name="selector">
<input type="checkbox" value="2" name="selector">
<input type="checkbox" value="3" name="selector">
<a id="check">Check Items</a>

View 1 Replies

Web Forms :: Get Count Of Selected Items In ListBox Using C#

May 7, 2015

how to get selected items count in listbox (but not all items count only selected items count) 

View 1 Replies

DataSource Controls :: Count Items Returned From ObjectDataSource?

May 27, 2010

I am viewing items returned from a dataset in an Infragistics chart control. My problem is that due to a weak point in the control, I am left looking for a way to manipulate the height of the chart based on the count/number of items returned by the ObjectDataSource(DataSet).

Does anyone one have an existing C# sample they could let me view of accessing the count of records returned within the code-behind of a page that I could then use within a case statement to set the hight of the control?

View 7 Replies

.net - Maximum-Count Of Selected Items - Validator For ListBox?

Nov 15, 2010

i have asked myself if there is an easy way to check if a ListBox has a maximum of 5 selected items. There must be at least one and at most 5 items selected.Do i need a CustomValidator with server-side validation?

View 1 Replies

Web Forms :: Get Count Of Number Of Items In A Column Which Is Separated By Comma?

Sep 27, 2012

In a column, have many items separated by comma or whitespace. How to get count of the number of items that is separated by comma or whitespace.

For example, test column has data like 123456, 543213, 678895

How to count as 3

View 1 Replies

Forms Data Controls :: Listbox Control Items Count Shows 0?

Jun 25, 2010

I am working on a screen where in it has a typical 2 listboxes & 2 buttons(add/remove), so when these buttons are clicked the items have to move from one listbox to another. its all working fine with javascript.but the issue is, I am not able to get the items of the 2nd listbox in the codebehind. I tried with html & asp.net listbox controls. I even tried to access the listbox using Request.Form["ControlName"] - which gives a null value.In the listbox1 the data's are coming from database.The data's choose from listbox1 will be moved to listbox2. And again i have to update this data to one of database table.

View 3 Replies

AJAX :: Populate CheckBoxList With Count Of Items Like SnapDeal / Flipkart Using JQuery

Dec 23, 2015

I need to bind category and count of that catergory like snapdeal bind to checklistbox using json and jquery in asp.net...

View 1 Replies

Forms Data Controls :: Bind Checkbox List To Selected Items List?

May 27, 2010

I have a situation where I want to show the selected records out of total records for a product of an employee

1) There is a checkbox list bind to <List> of objects from object datasource (For total items in list)

2) Now I want to check the selected items for a particular record in this list

3) For this purpose I have another list of <List> selected items returned by data access layer (For selected items for that employee )

4) How do I bind the selected objects with the total items list ?

5) In spaghetti coding model it was all too easy just by binding the checkbox list with a sql data source and running a for each on form load

View 5 Replies

Web Forms :: Adding List Items To Drop Down Control From Generic List?

Feb 6, 2010

I have the following Students class:

[Code]....

I need the 1 since it's a foreign key in another table. For the life of me, I can't get this to work like this.

View 7 Replies

Web Forms :: Tab Index For List Items In Radio Button List Control

Oct 17, 2012

Is it possible to set tab index value for list items of ASP.Net RadioButtonList control.

View 1 Replies

Templates - Populate List Items In Dropdown List From Placeholder?

Feb 24, 2010

I'm designing my own custom control that contains a .NET dropdownlist. What I'm wondering is if it is possible to populate my dropdownlist with listitems placed in a placeholder? For example:

<asp:DropDownList ID="ddlFilter" runat="server" >
<asp:PlaceHolder ID="ListItemPlaceholder" runat="server"/>
</asp:DropDownList>

This doesn't work because the DropDownList control only allows ListItems as child controls. But, I want to do something similar to this so when the user includes my control on a page, they can do something like this:

<mytag:MyControl Mode="DropDown" runat="server">
<ListItemTemplate>
<asp:ListItem Text="C" Value="c"></asp:ListItem>
<asp:ListItem Text="E" Value="e"></asp:ListItem>
<asp:ListItem Text="B" Value="b"></asp:ListItem>
</ListItemTemplate>
</myTag:MyControl>

I know I can do this by dynamically adding the ListItems in the page code behind, but I'd like to avoid that if possible.

View 1 Replies

Drop Down List Has A SelectedValue Which Is Invalid Because It Does Not Exist In The List Of Items

Mar 25, 2011

I am getting this error yet I know it to be untrue.This is the code:

ddlPartnerOrganisation.DataSource = agency.AgencyGetListOfEYDN();
string temp = ddlPartnerOrganisation.SelectedValue.ToString();
ddlPartnerOrganisation.DataValueField = "AgencyID"
;
ddlPartnerOrganisation.DataTextField = "AgencyName"
;
ddlPartnerOrganisation.DataBind();

View 4 Replies

Select Values From A List, Where The Items Contain In A Different List Aswell?

Feb 5, 2010

Is it possible to select values from a List, where the items contain in a different list aswell?for example;

[Code]....

What I need are all the items from the first list "Items", where the string contains something from the second list "List".So I need something which returns the first 3 items (which contain the term "Item") from the first list.

View 3 Replies

How To Search And Count No Of Occurrence In List Of String

Apr 2, 2010

I ve a list of string List<string> that have more than 100000 records. Now i want to search a particular string and their occurence it list. Is there is any buit in method that can perform dis job???

List has BinarySearch method but it retrun the index...

can anyone writing efficient algo of searching n counting no Occurrence in List of string

the method should b like

[code]....

View 4 Replies

SQL Server :: List All Dates In Date Range When Selecting Count

Oct 11, 2010

Say I have a table called "Visits", and I want to create a query that counts the visits per day. The way I would accomplish this would be to create a query as such:

SELECT Count(VisitId) as VisitCount, Convert(varchar(32), VisitDateTime, 101) as VisitDate
FROM Visits
WHERE VisitDateTime BETWEEN '10/1/2010' AND '10/5/2010'
GROUP BY VisitDate

The problem I am trying to overcome is that if there were no visits in a given day, that day does not show in my list. For example, if there were 3 visits on the 1st, 2 on the 2nd, none on the 3rd, and 5 on the 4th, my result set would look like:

3, 10/1/2010
2, 10/2/2010
4, 10/4/2010

How can I create my query so that I get all days in the date range listed in the result set regardless of whether the VisitCount is zero?

View 1 Replies

Group List And Get A Count Of The Number Of Occurrences Sorted Descending

Feb 8, 2011

I have a list of ids properly stored in a List<>. I now need to Group list and get a count of the number of occurrences sorted descending.

Example:

List<string> aryIDs = new List<string>;
aryIDs.Add("1234");
aryIDs.Add("4321");
aryIDs.Add("3214");
aryIDs.Add("1234");
aryIDs.Add("4321");
aryIDs.Add("1234");

Would Produce:

"1234", 3
"4321", 2
"3214", 1

This would be easy in TSQL, but I would like to avoid the server roundtrip, unnecessary tables, etc. if possible.

Update: The VB.NET conversion for Ralph Shillington's answer below:

[code]....

View 2 Replies

Data Controls :: Display Online Visitors List And Count

May 7, 2015

I want to show visitor count along with online users . How i do this?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved