0
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..

Edited by mike_2000_17: Fixed formatting

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Modi2006
0

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

0

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.

0

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...

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.