Update1:
this is all looks great but there is big problem which i have been looking for and so far i havent found that yet. – see my comments in the code.
var custNames = LoadCustNames();
var custFirstInitials = (from cn in custNames
select cn.Name.Substring(0, 1).ToLower()
).Distinct();
foreach (var item in custFirstInitials)
{
bool has = list.Contains(item);
//the above line of code return true because its checking whether `list.Contains or item.Contails` this will always return true but what i want is something sequence checking the first loop checks for A (found? true) and second loop checks for B (false) and third loop checks for C (false) .......so that i can generate ahref based on whether its return true or false.
if (has)
{
//generate href
}
else
{
//disable href
}
}
i have updated my question and seems like the question was not clear..
so here you go….
i am trying to compare a string[] myArray with a string and if anything is unmatched then store it in a string.
for an example:
i have a list of custName starting with A, S & Z and compare with myArray
string[] myArray = { "a", "b", "c", "d", "e", "f", "g", .... "z"};
public class CustNames
{
public string Name { get; set; }
public CustNames() { }
public CustNames(string name)
{
Name = name;
}
}
public List<CustNames> LoadCustNames()
{
//connect to db and load the data.
List<CustNames> names = new List<CustNames>
{
new CustNames("Alan"),
new CustNames("Scoot"),
new CustNames("Shark"),
new CustNames("Alpha"),
new CustNames("Zebra")
};
return names;
}
//page_load event....
//...check for postback....
for (int i = 0; i < 5; i++)
{
string name = LoadCustNames()[i].Name.ToString();
ListItem(name);
}
List<char> HeaderOf = new List<char>();
protected void ListItem(string cust)
{
// need a way to compare with myArray...
char CheckMe = cust.Substring(0, 1).ToUpper()[0];
if (!HeaderOf.Contains(CheckMe))
{
HeaderOf.Add(CheckMe);
}
}
Disable it but still leave as href (clicking it won’t do anything but would still look like active link)
Don’t display as href
Use css class WhateverClassForStyle to style it the way you want.
I guess you are trying to get a list of first initials of customer names.
custFirstInitialsis nowIEnumerable<string>and you can do a loop on it or check against it if the href should be made or not.