arrays with for loop
-
hi, i have a dagrid..in that checkboxes are there with ids of 1,2,3; i am passing the ids to that grid are 2,1..accordig to my logic those checkeboxes(1,2) has to be checked =true for ids 1,2 it is working if i pass the 3,2 then only 2nd checkbox is checking if i pass the 3...then no checkbox is checked... last checkbox is not checking for the last id.. i wrote the code like this in the databound event strScheduleIds=strScheduleId.Split(',');(here the values i am getting which i passed from the otherpage .) for(i=0;i<strScheduleIds.Length;i++) { foreach(DataGridItem dg in dglist.Items) { if(dg.Cells[9].Text.ToString()==strScheduleIds[i].ToString() ) { ((CheckBox)dg.FindControl("chk1")).Checked=true; } } }
-
hi, i have a dagrid..in that checkboxes are there with ids of 1,2,3; i am passing the ids to that grid are 2,1..accordig to my logic those checkeboxes(1,2) has to be checked =true for ids 1,2 it is working if i pass the 3,2 then only 2nd checkbox is checking if i pass the 3...then no checkbox is checked... last checkbox is not checking for the last id.. i wrote the code like this in the databound event strScheduleIds=strScheduleId.Split(',');(here the values i am getting which i passed from the otherpage .) for(i=0;i<strScheduleIds.Length;i++) { foreach(DataGridItem dg in dglist.Items) { if(dg.Cells[9].Text.ToString()==strScheduleIds[i].ToString() ) { ((CheckBox)dg.FindControl("chk1")).Checked=true; } } }
Have you tried to debug your code?
strScheduleIds.Length - 1
in first for-loop? Aredg.Cells[9].Text.ToString()
andstrScheduleIds[i].ToString()
the same if you pass "3"?Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)