Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox Array convert from php

Status
Not open for further replies.

Kurt111780

Technical User
Nov 20, 2003
235
GB
In php I have a file browser with checkboxes. When the from is submitted the selected checkboxes are put into an array. How can I do this in ASP.Net C# ?

Here is my php code:
Code:
<input type=\"checkbox\" value=\"$hPath\" name=\"file[]\" />

Then on the page it submits to:

$arrayFileName = $_POST['file'];
     foreach ($arrayFileName as $fileName)
     {
          echo $fileName;
     }

It's only easy when you know how.
 
in the code behind file some thing like:

for (int i=0; i < myCheckboxlist.Items.Count; i++)
{

if (myCheckboxlist.Items.Selected)
{

Response.Write ( myCheckboxlist.Items.Text + "<br>";

}
}

hope this helps
 
Hi,

I'm not using checkboxlist or anything. I added a checkbox to the FileSystem treeview from obout.com. There could be any number of checkboxes depending on the directory contents.

Here is what I have:

Code:
		// Display Files.
		for (int i=0; i<listFiles.Length; i++)
		{
			sPath = HttpUtility.UrlPathEncode(relativePath + Path.GetFileName(listFiles[i]));
			oTree.Add (sID, sID+"_"+(i+1), "[red]<input type='checkbox' value='"+ sPath +"' name='myfile'>[/red]<a href='"+ sPath +"'>"+ Path.GetFileName(listFiles[i]) +"</a>", null, "page.gif", null);
		}

It's only easy when you know how.
 
Something liek this then:
Code:
            For Each ctl As Control In Me.Controls
                If TypeOf ctl Is HtmlInputCheckBox Then

                End If
            Next


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ok, I have this but its not working. I'm just starting to learn asp.net
Code:
    void getSelectedFiles()
    {
         ArrayList checkedFiles = new ArrayList();
        foreach(Control found in myfile.Controls)
        {
            if(found.GetType() == typeof(CheckBox))
            {
 	            if(((CheckBox)found).Checked)
 	            {
 		            checkedFiles.Add(found.Name);
 	            }
            }
        }

[red]CS0103: The name 'myfile' does not exist in the current context[/red]

It's only easy when you know how.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top