c# - How can I load checkboxes with dynamic names in a listbox, the names are populated from an XML having a <NAME> tag -
i have following xml,
<?xml version="1.0" encoding="utf-8"?> <test> <name>testrun</name> <syncbyte>ff</syncbyte> <som>53</som> <pdadd>7e</pdadd> <lenlsb>08</lenlsb> </test>
i have defined listbox in wpf , have added single checkbox inside hoping can manage checkboxes dynamically. requirement that, can have multiple xmls 1 above different tag in them. need load listbox value of tag each xml, checkbox.
design:
as first need create test class
public class test { public string name { get; set; } public string pdadd { get; set; } }
you can load xml file xml serializer:
test obj; xmlserializer xs = new xmlserializer(typeof(test)); using (xmlreader xr = xmlreader.create("yourxmlfile.xml")) { obj = (test)xs.deserialize(xr); }
after that, attach obj
datasource
of checkbox-list , use databind()
of finally. markup of checkbox-list should set desired datavaluefield
, datatextfield
"name" (property name
of test). can xml contain duplicated item names, have provide id in xml, too. in case, set datavaluefield
"id".
also suggest follow standards upper , lowercase in names. change "test" "test" , "pdadd" "pdadd".
Comments
Post a Comment