string str = ""; 
        for (int i = 0; i < 2; i++) 
        {
        foreach (RepeaterItem r in Repeater1.Items)
        {

            CheckBox c = (CheckBox)r.FindControl("chkModule");
            //Response.Write(i); 

            if (c.Checked)
            {
                str += "true,";
                //Response.Write("True" + "&nbsp;&nbsp;&nbsp;" + str + "&nbsp;&nbsp;&nbsp;<br />");
                //Response.Write("True" + "&nbsp;&nbsp;&nbsp;" + str + "&nbsp;&nbsp;&nbsp;" + i + "<br />");
                // do some coding here...

            }
            else
            { 
                str+= "false,";
                //Response.Write("False" + "&nbsp;&nbsp;&nbsp;" + str + "&nbsp;&nbsp;&nbsp;<br />");
                //Response.Write("False" + "&nbsp;&nbsp;&nbsp;" + str + "&nbsp;&nbsp;&nbsp;" + i + "<br />");
            }

        }
         Response.Write(str+"#"+i+"#");

i have problem with build string using the following code...

and the output for this code is :

false,true,#0#false,true,false,true,#1# 

but i need to get this result :

false,#0#true,#1#

please any help will be highly appreciated..

Recommended Answers

All 4 Replies

r u trying to fetch 2 rows from Repeater Control..
or you are willing to iterate through out the items..?

I'm struggling to see the reason for the result you're trying to get - currently you're looping every item of the repeater twice, which seems unnecessary for this output.

To get the output in the form you want, try moving the point where the "#" + i + "#" is added to the string.. ..like so:

string str = ""; 
for (int i = 0; i < 2; i++) 
{
foreach (RepeaterItem r in Repeater1.Items)
{

CheckBox c = (CheckBox)r.FindControl("chkModule");

if (c.Checked)
{
str += "true,";
}
else
{ 
str += "false,";
}
str += "#"+i+"#";
}
Response.Write(str);

But be careful you know what the 'i' is indicating.

thank you all
but the i was but the output in wrong format i want the output to be :
true,#0#!false,#1#!
that is all
thanks for professionals...

thank you all
but the i was but the output in wrong format i want the output to be :
true,#0#!false,#1#!

and this is the solution :

string str = "";
        foreach (RepeaterItem r in Repeater1.Items)
        {
            CheckBox c = (CheckBox)r.FindControl("chkModule");

            for (int i = 1; i < 3; i++)
            {
                if (i == r.ItemIndex + 1)
                {
                    if (c.Checked)
                    {
                        str += i + "#true,";
                    }
                    else
                    {
                        str += i + "#false,";
                    }
                }
                else { str += ""; }
            }

        }
        Response.Write(str);

and special thank to mikev2 for help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.