BinarySearch() Not Locating Items In A Generic Collection?
May 14, 2010
When I dump the contents of a List<string>, I get:
Sue
Larry
John Barrowman
Bob
However, when I try to retrieve the index of the strings using this format...
thisIndex = blockRetrievedList.BinarySearch("Sue");
and print the indexes in an HTML list, here's the results that I get...
Using blockRetrievedList.BinarySearch('Larry'); : 1
Using blockRetrievedList.BinarySearch('Mike'); : -5
Using blockRetrievedList.BinarySearch('Sue'); : -5
Using blockRetrievedList.BinarySearch('Bob'); : -1
Using blockRetrievedList.BinarySearch('John Barrowman'); : -1
So while Larry comes out fine at index one, John Barrowman and Bob should be indexes 2 & 3 respectively. However, they're coming up -1 meaning they're not recognized as being the collection. Further Mike (who was originally in the set, but who has now been replaced by John Barrowman is coming up -5. Isn't that supposed to be -1? And why on Earth is Sue (who is index 0, returning -5 as well?
View 10 Replies
Similar Messages:
Oct 30, 2010
What is the difference between generic and non-generic collection?
View 1 Replies
Sep 16, 2010
I have GridView bound to some List. In layout I created following template field:
<asp:TemplateField HeaderText="Phrase">
<ItemTemplate>
<asp:TextBox ID="phraseTextBox" runat="server" Text='<%# Bind("Phrase") %>'/>
</ItemTemplate>
</asp:TemplateField>
But after changing the content of any TextBox in column "Phrase" my List doesn't reflect that changes.
View 2 Replies
Mar 7, 2010
I was building an application for a project with .NET 3.5 and I noticed a weird behaviour of the List.Add method:
I have built my own class to organize data pulled from a database, and I use a while cycle to iterate through it.
However, when I List.Add(item), the whole content of the list is substituted with the last content pulled.
An example:
Suppose you have 3 users in a DB, each one identified with an ID and a username:
| ID | username |
| 1 | John |
| 2 | Fred |
| 3 | Paul |
and you have a "Users" class defined as
public class Users
{
private Int32 iD;
private String username;
public Int32 ID
{
get { return iD; }
set { iD = value; }
}
public String Username
{
get { return username; }
set { username = value; }
}
}
So you write this function:
[... SQL definitions - sdr is a SqlDataReader ...]
List<Users> userlist = new List<Users>();
if (sdr.HasRows) //There are users
{
Users user = new Users();
while (sdr.Read())
{
user.ID = sdr.GetInt32(0);
user.username = sdr.GetString(1);
userlist.Add(user);
}
}
What you expect (I expect) is userlist containing:
| ID | username |
| 1 | John |
| 2 | Fred |
| 3 | Paul |
What I actually get is, instead
| ID | username |
| 3 | Paul |
| 3 | Paul |
| 3 | Paul |
View 3 Replies
Mar 8, 2010
I'm receiving this error in my Linq statement ---
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'hcgames.ObjectClasses.ShoppingCart.ShoppingCartCartAddon'. An explicit conversion exists (are you missing a cast?)
From this query
ShoppingCartItems items = Cart.GetAllItems();
ShoppingCartCartAddons addons = Cart.GetAllAddons();
var stuff = from x in items
select new ShoppingCartItem()
{
ProductID = x.ProductID,
Quantity = x.Quantity,
Name = x.Name,
Price = x.Price,
Weight = x.Weight,
Addons = (from y in addons
where y.ShoppingCartItemID == x.ID
select y)
};
View 2 Replies
Aug 22, 2010
I need to cache System.Collection.Generic.List object with expiration time
var Root = from feed in feedhotel.Descendants(ota + "HotelContent")
where (feed.Attribute("HotelCode") != null)
select new xmlhotel()
{
};
return Root.ToList();
Is it possible to cache Root.ToList() for some time....
View 1 Replies
Oct 22, 2012
I need a list to export in excel and i need the following to achieve in the exported excell
- I need the header of the excel with font bold and size should be 14px of font.
- Other Cell try should be 12px of the font
- Right align the particular column in the excel
View 1 Replies
Nov 8, 2010
I can bind to properties in the ViewModel fairly simply like so:
<%=Html.RadioButtonFor(m => m.isCool, true%>cool<br/>
<%=Html.RadioButtonFor(m => m.isCool, false)%>not cool<br/>
but what if I wanted to bind to collection items within the ViewModel. I'm not sure if it's possible. Here's what I have:
My ViewModel:
[code]....
I'm getting the following error: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
View 1 Replies
Dec 2, 2010
I have a collection of items in a model that I am looping through to display a very simple editable grid like this
[Code]....
but the values typed in in the textboxes do not appear to be anywhere in the model post data , does anyone have any pointers , this mustbe a common scenario and just cant find solution.
View 2 Replies
Jul 12, 2010
I'm trying to do this: Editing a variable length list, ASP.NET MVC 2-style
In the post he mentions that it could be done with less code using Html.EditorFor(), but that it would be more difficult because of the indexes. Well, that's exactly what I want to do, and I don't know where to begin.
Update 1: Instead of generating a GUID for each item in the collection, I'd like to generate incremental indexes starting with 0. Right now the field names look like "gifts[GUID].value"; I would like them to be "gifts[0].value","gifts1.value" etc. but I don't understand how the collection keeps track and generates these indices.
View 1 Replies
Apr 19, 2014
i want to check my collection so i can add a new customer as long as the username does not exist in the collection i do not want 2 customers to be able to have the same username.
i have been trying many different things to try to get this to work but i am not exactly sure what i should be doing I have a aspforum and collection C# class of the list.
here is some things that i have tried
CustomerExists() i also have a collection of List<Customers>
//HERE IS MY EXISTS METHOD
public static Boolean IfCustomerExists(string login) {
List<Customer> theGuy = Collections.Customers;
bool exist = false;
foreach (Customer customer in theGuy)
[Code]....
View 1 Replies
Feb 24, 2010
I have an ASP page with the following repeater:
[code]....
Why is the collection empty, when there are controls drawn on the screen?
(BTW: I tried adding/removing the EnableViewState="true" tag)
View 3 Replies
Dec 14, 2010
[code]....
Above is my select query result. "Select Groupname from table". Now i want to add dynamit row in table which display like follows.
[code]....
so that i can display the combobox with default value '-Select-'. I tried combobox.item.insert(0.'"Select") but it gives error.
"Items collection cannot be modified when the DataSource property is set."
so I am trying to add dynamically into table.
View 5 Replies
Feb 17, 2010
I got 2 listboxes in a window form, one on left and one on right. The 1st listbox have some items while the 2nd listbox is empty. Also there are 2 buttons between the 2 listboxes which used to move item from/to the 1st and 2nd listbox.My problem here is that after I bind the data to the 1st listbox (from a dataTable, using DisplayMember and ValueMember) , and I try to move 1 of the item from this 1st listbox to the 2nd listbox and I want that the selected item is also removed from the 1st listbox by:
lbMembers2.Items. Add(lbMembers1. Text);
lbMembers1.Items. Remove(lbMembers 1.Text);
But the selected item is not removed from the 1st listbox.Also on deselect button when i move item from 2nd listbox to 1st listbox,it displays error message "Items collection cannot be modified when the DataSource property is set."
View 2 Replies
Feb 25, 2011
I have an ASCX control which is a special dropdownlist. I add that control dynamically to the page and fill it with data. This control has a postback that will change the contents of a second dynamically created standard dropdownlist.
When I change the selection on the first dropdown, the indexchanged fires and I get new data and attempt to place it in the second dropdownlist's items collection, by first clearing it then filling it with new data.
This works fine the first time a change the selection, but when I select a second time the following error is thrown:
The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.
I'm not adding or removing new controls in the fired event, only changing data. And again, it works the first time, but doesn't subsequent times.
If I disable stateview on the child control, then the control just doesn't get updated with data at all.
View 1 Replies
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
Sep 20, 2010
I do know there are 2 types or rewrites setup for this site.
One I can locate and is solely responsible for top level rewrites (turning .com to .co.uk)
There is another rewriter implemented somehow somewhere, very early on in a pages lifecycle and I cannot find how or where the site is doing this. It's possible it's all handled in a 3rd party DLL but I would like to know the steps I might go through to prove or disprove this.
View 3 Replies
Oct 3, 2010
I buildt an application which stores the values of the visiters of our website. date of visit, browser type, ip address, etc. I just what to locate their location according to ip address automatically. How can I do that? do I need to use a external database to retrive ip address locations?
View 2 Replies
Mar 4, 2011
Another problem I am having is I have an image at the top right of a page and I want it to be hard against the edge of the page with no border and I am really struggling to get this to happen.
View 1 Replies
Jan 26, 2010
i installed both of VS2008 and VS2010 on my laptop.when i want to connect sql bank 2005 i got this error
http://uploadpic.org/showpic-42108/untitled_1.jpgi installed SQLEXPR for windows 7 64bitbut it didn't work. there is nothing istance of sql 2005 in SQL Server Configuration Manager
View 2 Replies
Jul 26, 2010
I have a list of objects that I want to bind to a gridview. Creating that list and binding it works fine for most of the public properties in that list.
There are some objects contained in each of those objects... for instance there is an Address object.
object.Address.Line1;
object.Address.Line2;
When I bind this to my gridview, I have no issues with stuff like object.DateRegistered, but how can I access things like object.Address.WhatEverProperty? I always get this error:
"A field or property with the name 'xxx.xxxx' was not found on the selected data source."
View 7 Replies
Mar 31, 2010
I want to know that how i use the collection class for storing some data and save it letter in the data base.
View 4 Replies
Nov 25, 2010
I'm trying to create a control out of a class I found, and one of the overridden functions is the following:
protected override void PerformDataBinding(IEnumerable data)
However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.
View 3 Replies
Mar 25, 2011
I have an ASP.NET app with lots of textboxes all over the page that need updating at various points through program execution.
These textboxes actually belong to a certain class, so for easy updating I thought I could create a Dictionary(Of string, object) and add the control.ID and the control to it and then for updating do something like this:
(in case of updating textbox.text):
[code]....
However the text property of the textbox does not actually get updated. I'm mainly trying to avoid having to manually do textbox.text = somestring for each one of my textboxes every time I have to update them.
View 3 Replies
Jan 19, 2011
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
when i upload my site on webserver and connect with remote sqlserver2005 using connection string....
<connectionStrings>
<remove name="ConnectionString"/>
<add name="ConnectionString" connectionString="Data Source=69.16.253.19,1433;Initial [code]...
it shows an error above ..i m using aspnetdb.mdf in my website in APP_Data Folder... features i use in my website is Login Control, Password recovery, signup control...
View 2 Replies