Displaying JsonArray inside JsonObject into ListView - c#

I have a json like the image below:
I want to put the json into a listview (inside the listview there is a webview to display the text (which I circled in blue), which is in order according to its index (which I circled in black)).
XAML:
<ListView
Name="ListPairOption"
Height="auto"
Margin="5,0,10,0">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:PairClass">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel
x:Name="pilganStack"
Grid.Column="0"
Margin="10,10,10,10">
<WebView
x:Name="option"
MaxWidth="600"
MaxHeight="300"
Margin="5,5,5,5"
local:MyProperties.HtmlString="{Binding Name}"/>
</StackPanel>
</ListView
Code:
string urlPath = "..../multiple/test/284/4";
var httpClient = new HttpClient(new HttpClientHandler());
httpClient.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", "token"));
var response = await httpClient.GetAsync(urlPath);
string jsonText = await response.Content.ReadAsStringAsync();
try
{
JsonObject jsonObject = JsonObject.Parse(jsonText);
JsonObject questionObject = jsonObject["EXAM_QUESTION"].GetObject();
int index = 0;
string c = "";
string v1 = "";
string choice = "";
ObservableCollection<PairClass> itemL = new ObservableCollection<PairClass>();
JsonArray mapArray = questionObject["map"].GetArray();
foreach (JsonValue mapValue in mapArray)
{
JsonArray mapArrayI = mapValue.GetArray();
foreach (JsonValue mapValueI in mapArrayI)
{
PairClass pair = new PairClass();
try
{
if (mapValueI.ToString().All(char.IsDigit))
{
c = String.Concat(mapValueI.ToString().Where(Char.IsDigit));
index = Int16.Parse(c);
pair.Ind = index;
}
else
{
string v = mapValueI.ToString();
var collection = Regex.Matches(v, "\\\"(.*?)\\\"");
foreach (var item in collection)
{
v1 = item.ToString().Trim('"');
choice = v1;
pair.Name = choice;
}
}
for (int i = 0; i < varian; i++)
{
itemL.Add(new PairClass { Ind = index, Name = choice });
}
itemL.Add(pair);
}
}
}
ListPairOption.ItemsSource = itemL;
}
Pair Class:
public class PairClass
{
public int Ind { get; set; }
public string Name { get; set; }
public PairClass()
{
Ind = int.MinValue;
Name = string.Empty;
Pilihan = string.Empty;
}
public PairClass(int ind, string name)
{
Ind = ind;
Name = name;
}
}
I'm having a problem, which can't display data into a ListView (only the last data is shown repeatedly in the listview), as shown below:
How to handle it?

I checked your code, it looks you generated PairClass in wrong place, it should be created before map item parsed and assigned value after each map item parsed. I have updated the code below, please check it.
try
{
JsonObject jsonObject = JsonObject.Parse(jsonText);
JsonObject questionObject = jsonObject["EXAM_QUESTION"].GetObject();
int index = 0;
string c = "";
string v1 = "";
string choice = "";
ObservableCollection<PairClass> itemL = new ObservableCollection<PairClass>();
JsonArray mapArray = questionObject["map"].GetArray();
foreach (JsonValue mapValue in mapArray)
{
JsonArray mapArrayI = mapValue.GetArray();
PairClass pair = new PairClass();
foreach (JsonValue mapValueI in mapArrayI)
{
try
{
if (mapValueI.ToString().All(char.IsDigit))
{
c = String.Concat(mapValueI.ToString().Where(Char.IsDigit));
index = Int16.Parse(c);
pair.Ind = index;
}
else
{
string v = mapValueI.ToString();
var collection = Regex.Matches(v, "\\\"(.*?)\\\"");
foreach (var item in collection)
{
v1 = item.ToString().Trim('"');
choice = v1;
pair.Name = choice;
}
}
}
catch
{
}
}
itemL.Add(pair);
}
ListPairOption.ItemsSource = itemL;
}
catch
{
}

Related

How to read data from any file and insert to class object using c#

I am reading a data from CSV file and trying to add to object. but when i add new record by looping through records the data in object is getting overridden.
public static void Process()
{
var path= #"ABC.csv";
var header = false;
var lines = System.IO.File.ReadAllLines(filePath);
var element = new List<Content>();
var mapTo = new Content();
for (var i = 0; i < lines.Length; i++)
{
var t = lines[i];
if (!header)
{
header = true;
}
else
{
var data = t.Split(',');
mapTo.Key= data[0];
mapTo.Name= data[1];
mapTo.Number= data[2];
mapTo.Date= data[3];
element.Add(mapTo);
}
}
var result = element;
}
so here when i try to add mapTo to element all the content in element variable is getting overridden.Can anybody suggest what's wrong i am doing here.
Move var mapTo = new Content(); into the for loop. Otherwise you have the same instance of Content for each loop iteration which gets overriden by the assigenments in the for loop.
public static void Process()
{
var path= #"ABC.csv";
var header = false;
var lines = System.IO.File.ReadAllLines(filePath);
var element = new List<Content>();
for (var i = 0; i < lines.Length; i++)
{
var mapTo = new Content(); //here
var t = lines[i];
if (!header)
{
header = true;
}
else
{
var data = t.Split(',');
mapTo.Key= data[0];
mapTo.Name= data[1];
mapTo.Number= data[2];
mapTo.Date= data[3];
element.Add(mapTo);
}
}
var result = element;
}

Get duplicate Realtime Database Firebase results in Xamarin

I'm trying to build realtime chat through Realtime Database Firebase and Xamarin. However there is a problem like this, hope someone can help:
protected async void LoadChat()
{
string userid = "123456789";
var getroom = (await fc.Child("RecordsChat").OnceAsync<GetRoomChats>()).Select(x =>
new GetRoomChats
{
RoomID = x.Key
}).ToList();
List<GetRoomChats> listroomuser = new List<GetRoomChats>();
foreach (var room in getroom)
{
string str = null;
string[] strArr = null;
string roomget = room.RoomID;
str = roomget + "_";
char[] splitchar = { '_' };
strArr = str.Split(splitchar);
var getroomuser = strArr.Distinct().ToList();
foreach (var item in getroomuser)
{
if (item == userid)
{
var roomgetuser = new GetRoomChats()
{
RoomID = roomget
};
listroomuser.Add(roomgetuser);
}
}
}
if (listroomuser.Count() > 0)
{
var FirebaseClient = fc
.Child("RecordsChat")
.AsObservable<GetRoomChats>()
.Subscribe(async(dbevent) =>
{
//IteamGetRoomChats.Clear();
foreach (var room in listroomuser)
{
if (dbevent.Key == room.RoomID)
{
var lst = (await fc.Child("RecordsChat").Child(dbevent.Key).OrderByKey().LimitToLast(1).OnceAsync<MyDatabaseRecord>()).Select(x =>
new MyDatabaseRecord
{
NameUser = x.Object.NameUser,
Content = x.Object.Content,
RoomID = x.Object.RoomID,
DayCreate = x.Object.DayCreate,
AvatarUser = x.Object.AvatarUser,
sender_uid = x.Object.sender_uid,
receiver_uid = x.Object.receiver_uid,
receiver_read = x.Object.receiver_read
});
bool unread = false;
foreach (var i in lst)
{
if(i.sender_uid == userid)
{
i.Content = "You: " + i.Content;
var customerList = await apiServiceUserinfo.GetCustomersInfo(i.receiver_uid);
string nameget = customerList.NameStore;
string avatarget = customerList.AvatarStore;
i.NameUser = nameget;
i.AvatarUser = avatarget;
if (i.sender_read == true)
{
unread = false;
}
}
else
{
if (i.receiver_read == false)
{
i.BackgroundUser = "#f5f4f4";
unread = true;
}
}
var last = new GetRoomChats()
{
NameLast = i.NameUser,
ContentLast = i.Content,
RoomID = i.RoomID,
DayCreateLast = i.DayCreate,
AvatarLast = i.AvatarUser,
BackgroundUnread = i.BackgroundUser,
DotUnread = unread
};
IteamGetRoomChats.Add(last);
}
}
}
});
}
BindingContext = this;
}
In my example above, it actually gets the data. I try to check in the loop, to get the last content of the message. However, the displayed results are duplicated
Looking forward to everyone's help. Thank you!

How to get the second element in the list

I have question how can I get second value (next value) of unixDate? How could I achieve this??
getData window:
public static List<Tuple<string, string>> euDataDaily(string url)
{
var aTuple = new List<Tuple<string, string>> { };
WebClient c = new WebClient();
var data = c.DownloadString(url);
JObject o = JObject.Parse(data);
string conditionCode="";
string unixDate = "";
string dayTemp="";
foreach (var result in o["daily"])
{
unixDate = (string)result["dt"];
string day = unixDate;
if (unixDate.Equals(day))
{
dayTemp = (string)result["temp"]["day"];
}
if (unixDate.Equals(day))
{
foreach (var res in result["weather"])
{
conditionCode = (string)res["description"];
}
}
}
aTuple.Add(Tuple.Create(dayTemp, conditionCode));
return aTuple;
}
EDIT: I need to get second "dt" value.
Data:
{"lat":56.94,"lon":24.1,"timezone":"Europe/Riga","timezone_offset":10800,"daily":[{"dt":1617703200,"sunrise":1617680352,"sunset":1617729143,"temp":{"day":6,"min":-1.1,"max":7.55,"night":1.3,"eve":5.46,"morn":-1.1},"feels_like":{"day":2.15,"night":-6.52,"eve":1.56,"morn":-6.52},"pressure":993,"humidity":61,"dew_point":-0.83,"wind_speed":6.05,"wind_deg":241,"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":75,"pop":0.58,"snow":0.11,"uvi":2.12},
{"dt":1617789600,"sunrise":1617766591,"sunset":1617815670,"temp":{"day":6.78,"min":-0.52,"max":7.42,"night":1.41,"eve":6.13,"morn":-0.52},"feels_like":{"day":3.71,"night":-4.96,"eve":3.57,"morn":-4.96},"pressure":1001,"humidity":40,"dew_point":-5.88,"wind_speed":4.67,"wind_deg":216,"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":15,"pop":0.62,"snow":0.22,"uvi":2.03},{"dt":1617876000,"sunrise":1617852830,"sunset":1617902197,"temp":{"day":4.38,"min":-0.44,"max":5.07,"night":1.3,"eve":4.02,"morn":0.62},"feels_like":{"day":-0.01,"night":-2.81,"eve":0.96,"morn":-2.81},"pressure":1009,"humidity":53,"dew_point":-4.45,"wind_speed":6.28,"wind_deg":323,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":77,"pop":0.2,"uvi":2.27},
{"dt":1617962400,"sunrise":1617939069,"sunset":1617988724,"temp":{"day":6.12,"min":0.14,"max":7.58,"night":5.43,"eve":7.04,"morn":0.3},"feels_like":{"day":2.03,"night":-4.37,"eve":3.1,"morn":-4.37},"pressure":1015,"humidity":55,"dew_point":-2.05,"wind_speed":6.78,"wind_deg":207,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":78,"pop":0.17,"uvi":2.38},{"dt":1618048800,"sunrise":1618025309,"sunset":1618075252,"temp":{"day":6.91,"min":4.2,"max":8.85,"night":5.84,"eve":8.85,"morn":4.2},"feels_like":{"day":4.17,"night":0.35,"eve":6.67,"morn":0.35},"pressure":1014,"humidity":74,"dew_point":2.54,"wind_speed":4.07,"wind_deg":216,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":100,"pop":0.39,"rain":0.49,"uvi":2.56},{"dt":1618135200,"sunrise":1618111550,"sunset":1618161779,"temp":{"day":4.54,"min":4.48,"max":5.66,"night":5.14,"eve":5.09,"morn":5.29},"feels_like":{"day":2.15,"night":5.29,"eve":2.3,"morn":5.29},"pressure":1017,"humidity":96,"dew_point":4,"wind_speed":2.74,"wind_deg":358,"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"clouds":100,"pop":1,"rain":10.84,"uvi":3},
{"dt":1618221600,"sunrise":1618197791,"sunset":1618248307,"temp":{"day":10.63,"min":4.78,"max":11.88,"night":4.78,"eve":7.64,"morn":7.95},"feels_like":{"day":9.99,"night":5.74,"eve":4.6,"morn":5.74},"pressure":1017,"humidity":86,"dew_point":8.42,"wind_speed":3.31,"wind_deg":190,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":100,"pop":0.98,"rain":4.16,"uvi":3},
{"dt":1618308000,"sunrise":1618284033,"sunset":1618334834,"temp":{"day":5.87,"min":2.34,"max":7.02,"night":3.39,"eve":5.9,"morn":2.34},"feels_like":{"day":2.87,"night":-2.08,"eve":3.91,"morn":-2.08},"pressure":1027,"humidity":55,"dew_point":-2.38,"wind_speed":4.11,"wind_deg":268,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":90,"pop":0.2,"rain":0.11,"uvi":3}]}
Thanks for response.

Compare two lists of same type

I need to compare two lists of same type. Assume I have CurrentSC List(Current modified data by user) and PreviousSC List(Saved data from database) of below class.
public class SoftClose
{
private int AID = -1;
private bool _softCloseInd;
private bool _softCloseEditInd;
private string _softClosedBy;
private DateTime _softClosedDate;
private ReferenceEnums.ActionStatus _status = ReferenceEnums.ActionStatus.NO_CHANGE;
}
public static void TPostProcessAddRemoveSoftCloseStopPaymentPrefixes(IFPMServiceInternal fpmService, AgreementRevision revision)
{
List<SoftClose> psc = null;
List<SoftClose> csc = null;
string fanValue = revision.Agreement.FAN;
psc = fpmService.GetSoftCloseByFAN(fanValue);
if (psc != null)
{
//var currentprefixes = revision.Details.Where(x => x.Prefix != null).Select(y => y.Prefix).Distinct();
//Create current SoftClose object using revision object
foreach (var prefix in revision.Details.Where(x => x.Prefix != null).Select(y => y.Prefix).Distinct())
{
var newSF =
new SoftClose
{
Id = -1,
Status = ReferenceEnums.ActionStatus.NO_CHANGE,
AgreementRevId = revision.Id,
AgreementId = revision.Agreement.Id,
WorkflowStatus = revision.WorkflowStatus,
FAN = revision.Agreement.FAN,
PID = (int)revision.Agreement.PID,
Prefix = prefix
};
csc.Add(newSF);
}
//Now you have previous and current softcloses to compare prefixes...
psc.OrderBy(x => x.Prefix.Id);
csc.OrderBy(x => x.Prefix.Id);
for(int i = 0; i < csc.Count; i++)
{
}
}
}
Lets say I have changed D3 value in PreviousSC to D2 in CurrentSC. Now i need to delete D3 value from database(As D2 value already there in database i don't need to insert) and chnage _status to DELETE and I added D4 value in CurrentSC which is not there is PreviousSC. Now I need to add D4 value in database and assign _softCloseInd and _softCloseEditInd to Y and change _status to ADD.
How to achieve this in best way?
class Program
{
static void Main(string[] args)
{
List<SoftClose> psc = new List<SoftClose>(){
new SoftClose(){ID=1, Status = "NO_CHANGE",AID=19, Prefix = "D1"},
new SoftClose(){ID=2, Status = "NO_CHANGE",AID=20, Prefix = "D2"},
new SoftClose(){ID=3, Status = "NO_CHANGE",AID=21, Prefix = "D3"},
new SoftClose(){ID=3, Status = "NO_CHANGE",AID=22, Prefix = "D9"}
};
List<SoftClose> csc = new List<SoftClose>(){
new SoftClose(){ID=-1, Status = "NO_CHANGE",AID=19, Prefix = "D2"},
new SoftClose(){ID=-1, Status = "NO_CHANGE",AID=20, Prefix = "D2"},
new SoftClose(){ID=-1, Status = "NO_CHANGE",AID=21, Prefix = "D6"},
new SoftClose(){ID=-1, Status = "NO_CHANGE",AID=22, Prefix = "D4"},
new SoftClose(){ID=-1, Status = "NO_CHANGE",AID=23, Prefix = "D5"},
new SoftClose(){ID=-1, Status = "NO_CHANGE",AID=24, Prefix = "D3"}
};
List<SoftClose> esc = new List<SoftClose>();
Console.WriteLine("---------Previous List----------");
foreach (var item in psc)
{
Console.WriteLine($"Id:{item.ID}, Desc1:{item.Prefix}, Status:{item.Status}");
}
Console.WriteLine("--------------------------------------");
Console.WriteLine("---------Current List----------");
foreach (var item in csc)
{
Console.WriteLine($"Id:{item.ID}, Desc1:{item.Prefix}, Status:{item.Status}");
}
Console.WriteLine("--------------------------------------");
var addlist = csc.Where(c => psc.All(p => !p.Prefix.Equals(c.Prefix)));
foreach (var n in addlist)
{
var index = csc.FindIndex(p => p.Prefix.Equals(n.Prefix));
csc[index].Status = "ADD";
esc.Add(csc[index]);
}
var deletelist = psc.Where(p => p.Status.Equals("NO_CHANGE") && !csc.Exists(c => c.Prefix.Equals(p.Prefix)));
foreach (var n in deletelist)
{
var index = psc.FindIndex(c => c.Prefix.Equals(n.Prefix));
if (psc.FindIndex(c => c.Prefix.Equals(n.Prefix)) >= 0)
{
psc[index].Status = "REMOVE";
esc.Add(psc[index]);
}
}
Console.WriteLine("---------Effective List----------");
foreach (var item in esc)
{
Console.WriteLine($"Id:{item.ID}, Prefix:{item.Prefix}, Status:{item.Status}");
}
Console.ReadLine();
}
}
public class SoftClose
{
public int ID = -1;
public int AID = -1;
public int WFID = -1;
public string Prefix;
public DateTime SCDATE;
public string Status;
}

Dropdownlist with optgroup using WebControlAdapters

I need to do a dropdownlist with optgroup.
I found lots of guides and all foresee the use of WebControlAdapter
this is the guide that I'm fllowing
I've added the class to my App_Code folder project:
namespace admin.App_Code
{
public class DropDownListAdapter :
System.Web.UI.WebControls.Adapters.WebControlAdapter
{
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
// The current control being "adaptered" is available within context from the Control property
DropDownList dropDownList = (DropDownList)Control;
ListItemCollection items = dropDownList.Items;
// Retrieve Optgrouping using LinQ
var groups = (from p in items.OfType<ListItem>()
group p by p.Attributes["Group"] into g
select new { Label = g.Key, Items = g.ToList<ListItem>
() });
foreach (var group in groups)
{
if (!String.IsNullOrEmpty(group.Label))
{
writer.WriteBeginTag("optgroup");
writer.WriteAttribute("label", group.Label);
writer.Write(">");
}
int count = group.Items.Count();
if (count > 0)
{
bool flag = false;
for (int i = 0; i < count; i++)
{
ListItem item = group.Items[i];
writer.WriteBeginTag("option");
if (item.Selected)
{
if (flag)
{
throw new HttpException("Multiple selected items not allowed");
}
flag = true;
writer.WriteAttribute("selected", "selected");
}
if (!item.Enabled)
{
writer.WriteAttribute("disabled", "true");
}
writer.WriteAttribute("value", item.Value, true);
if (this.Page != null)
{
this.Page.ClientScript.RegisterForEventValidation(dropDownList.UniqueID, item.Value);
}
writer.Write('>');
HttpUtility.HtmlEncode(item.Text, writer);
writer.WriteEndTag("option");
writer.WriteLine();
}
}
if (!String.IsNullOrEmpty(group.Label))
{
writer.WriteEndTag("optgroup");
}
}
}
private Object _ViewState;
protected override void OnLoad(EventArgs e)
{
if (Page.IsPostBack)
{
if (_ViewState != null)
{
Object[] groups = (Object[])_ViewState;
DropDownList dropDownList = (DropDownList)Control;
// Add saved optgroups to ListItems
for (Int32 i = 0; i < groups.Length; i++)
{
if (groups[i] != null)
{
dropDownList.Items[i].Attributes["Group"] = groups[i].ToString();
}
}
}
}
base.OnLoad(e);
}
protected override void LoadAdapterViewState(object state)
{
// Retrieve existing state
_ViewState = state;
}
protected override object SaveAdapterViewState()
{
DropDownList dropDownList = (DropDownList)Control;
Int32 count = dropDownList.Items.Count;
Object[] values = new Object[count];
// Retrieve Optgrouping from ListItem
for (int i = 0; i < count; i++)
{
values[i] = dropDownList.Items[i].Attributes["Group"];
}
return values;
}
}
}
public static void loadDDLModelli(ref DropDownList ddl, List<dynamic>
objects)
{
Int16 cont = 0;
ddl.Items.Clear();
System.Web.UI.WebControls.ListItem li;
String idModello = "";
String nomeModello = "";
String nomeBrand = "";
String oggetto = "";
List<System.Web.UI.WebControls.ListItem> items = new List<System.Web.UI.WebControls.ListItem>();
foreach (var item in objects)
{
oggetto = item.ToString().Replace("{", "").Replace("}", "");
idModello = oggetto.Split(',')[0].Split('=')[1].Trim();
nomeModello = oggetto.Split(',')[1].Split('=')[1].Trim();
nomeBrand = oggetto.Split(',')[2].Split('=')[1].Trim();
li = new System.Web.UI.WebControls.ListItem(nomeBrand+" - "+nomeModello, idModello);
li.Attributes["Group"] = nomeBrand;
items.Add(li);
cont++;
};
ddl.DataSource = items;
ddl.DataBind();
ddl.SelectedIndex = -1;
}
I've added the folder App_Browser to my project (did not exist) and I've added the file BrowserFile.browser
<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.WebControls.DropDownList"
adapterType="admin.App_Code.DropDownListAdapter" />
</controlAdapters>
</browser>
</browsers>
in my page .aspx (that is in the same folder of the class DropDownListAdapter I have
<asp:DropDownList runat="server" ID="ddlModelli" CssClass="form-control multipleSelect"></asp:DropDownList>
that is filled in this way
public static void loadDDLModelli(ref DropDownList ddl, List<dynamic> objects)
{
Int16 cont = 0;
ddl.Items.Clear();
System.Web.UI.WebControls.ListItem li;
String idModello = "";
String nomeModello = "";
String nomeBrand = "";
String oggetto = "";
List<System.Web.UI.WebControls.ListItem> items = new List<System.Web.UI.WebControls.ListItem>();
foreach (var item in objects)
{
oggetto = item.ToString().Replace("{", "").Replace("}", "");
idModello = oggetto.Split(',')[0].Split('=')[1].Trim();
nomeModello = oggetto.Split(',')[1].Split('=')[1].Trim();
nomeBrand = oggetto.Split(',')[2].Split('=')[1].Trim();
li = new System.Web.UI.WebControls.ListItem(nomeBrand+" - "+nomeModello, idModello);
li.Attributes["Group"] = nomeBrand;
items.Add(li);
cont++;
};
ddl.DataSource = items;
ddl.DataBind();
ddl.SelectedIndex = -1;
}
the problem is that, when I watch the source code I do not have the optgroup tag but only options tag.
In fact, if I put a breakpoint in the first line of the method RenderContents this doesn't fire.
What I'm doing wrong?
I solved the issue.
The problem was in the method LoadDDLModelli.
Instead of setting DataSource and do the DataBind to the Dropdownlist passed via reference, I have to add ItemList singoularly (I cannot understand the difference)
public static void loadDDLModelli(ref DropDownList ddl, List<dynamic> objects)
{
Int16 cont = 0;
ddl.Items.Clear();
System.Web.UI.WebControls.ListItem li;
String idModello = "";
String nomeModello = "";
String nomeBrand = "";
String oggetto = "";
List<System.Web.UI.WebControls.ListItem> items = new List<System.Web.UI.WebControls.ListItem>();
foreach (var item in objects)
{
oggetto = item.ToString().Replace("{", "").Replace("}", "");
idModello = oggetto.Split(',')[0].Split('=')[1].Trim();
nomeModello = oggetto.Split(',')[1].Split('=')[1].Trim();
nomeBrand = oggetto.Split(',')[2].Split('=')[1].Trim();
li = new System.Web.UI.WebControls.ListItem(nomeBrand+" - "+nomeModello, idModello);
li.Attributes["Group"] = nomeBrand;
items.Add(li);
cont++;
};
//ddl.DataSource = items;
//ddl.DataBind();
foreach(ListItem i in items)
ddl.Items.Add(i);
ddl.SelectedIndex = -1;
}

Categories

Resources