How to convert For loop to LINQ

3 posts, 0 answers
  1. Deekshith
    Deekshith avatar
    15 posts
    Member since:
    Mar 2014

    Posted 09 Apr 2014 Link to this post

    Hi Please Help me to Convert bellow Code Snippet to LINQ

    foreach (RadComboBoxItem item in rdComboNames.Items)
                    {
     
                        CheckBox chk = (CheckBox)item.FindControl("chk1");
                        if (i == 0)
                        {
                            checkedText += "Names:";
                        }
                        else if (chk.Checked)
                        {
                            checkedText += item.Text + ", ";
                        }
                        i++;
                    }
  2. Krsnaraja
    Krsnaraja avatar
    9 posts
    Member since:
    Aug 2007

    Posted 09 Apr 2014 in reply to Deekshith Link to this post

    Hello,

    Try this:
    checkedText = string.Concat("Names: ", string.Join(", ",
                rdComboNames.Items.Skip(1)
                    .Where(x => x.Checked)
                    .Select(x => ((CheckBox) x.FindControl("chk1")).Text)
                    .ToArray()));


    Thanks,
    Krishna Raja
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Deekshith
    Deekshith avatar
    15 posts
    Member since:
    Mar 2014

    Posted 09 Apr 2014 Link to this post

    Thank you. .
Back to Top