Tuesday, 15 March 2011

.net - How to set radio.IsChecked = true; to a particular radiobutton programatically using c# -



.net - How to set radio.IsChecked = true; to a particular radiobutton programatically using c# -

i working on silverlight , have created radiobutton want set manually check of radiobutton programatically given 3 items (itms means 3 radiobutton) on radio button.i tried this

radiobutton radio = new radiobutton();

suppose radio buttons contains " items( radio buttons) , when seek code below check sec item (out of 3 items) code below checks lastly item.

radio.loaded += (p, q) => { radio.ischecked = true; };

how create button :

foreach (string item in param.component.attributes[0].item) { radio = new radiobutton() { content = item, groupname = "myradiobuttongroup", tag = tg }; radio.checked += (o, e) => { //do }; sp.children.add(radio); count++; tg++; }

why checks lastly item ? how check sec item programatically usin silverlight in c# code? seek because want intialise radio button after programme launch (before button clicks) because on before button click of radio buttons if seek print itmes on text block, see nil (it show on button clicks want displayed before clicking instead of empty space)

the short reply question set radio.ischecked=truein code create radiobutton checked.

one way solve set ischecked = true when sec radio button added. since code in foreach loop count variable should work.

foreach (string item in param.component.attributes[0].item) { radio = new radiobutton() { content = item, groupname = "myradiobuttongroup", tag = tg }; radio.checked += (o, e) => { //do }; sp.children.add(radio); count++; tg++; if (count == 2){ radio.ischecked=true; } }

or alter foreach loop loop

for (int = 0; < param.component.attributes[0].item.count ; i++) { } if (i== 2){ radio.ischecked=true; }

while both these approaches work don't mesh databound approach mutual in silverlight applications. initial state of selected items should stored in state variable.

c# .net silverlight radio-button ischecked

No comments:

Post a Comment