Oppure

Loading
13/03/14 9:06
fusebyte
Ho scritto delle funzioni usando delle checkbox per controllarle ,per es:
if checkbox_MySwap.checked...
if checkbox_FXswitch.checked...
if checkbox_Mypiktur.checked...
if checkbox_Capcap.checked...
if checkbox_Trimsony.checked...
e cosi' via...


Non avendo mai usato oggetti t ipo CheckBoxList, DataGridView o altri e non sapendo quale possa essere quello che
piu' si addice al mio caso, ho cercato un po' di esempi in rete.
Per la CheckBoxList ho trovato questo:
<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
    <title> CheckBoxList Constructor Example </title>
<script runat="server">

      void Check_Clicked(Object sender, EventArgs e) 
      {

         // Retrieve the CheckBoxList control from the Controls collection
         // of the PlaceHolder control.
         CheckBoxList checklist = 
             (CheckBoxList)Place.FindControl("checkboxlist1");

         // Make sure a control was found.
         if(checklist != null)
         { 

            Message.Text = "Selected Item(s):<br /><br />";

            // Iterate through the Items collection of the CheckBoxList 
            // control and display the selected items.
            for (int i=0; i<checklist.Items.Count; i++)
            {

               if (checklist.Items[i].Selected)
               {

                  Message.Text += checklist.Items[i].Text + "<br />";

               }

            }

         }

         else
         {

            // Display an error message.
            Message.Text = "Unable to find CheckBoxList control.";

         }

      }

      void Page_Load(Object sender, EventArgs e)
      {

         // Create a new CheckBoxList control.
         CheckBoxList checklist = new CheckBoxList();

         // Set the properties of the control.
         checklist.ID = "checkboxlist1";
         checklist.AutoPostBack = true;
         checklist.CellPadding = 5;
         checklist.CellSpacing = 5;
         checklist.RepeatColumns = 2;
         checklist.RepeatDirection = RepeatDirection.Vertical;
         checklist.RepeatLayout = RepeatLayout.Flow;
         checklist.TextAlign = TextAlign.Right;

         // Populate the CheckBoxList control.
         checklist.Items.Add(new ListItem("Item 1"));
         checklist.Items.Add(new ListItem("Item 2"));
         checklist.Items.Add(new ListItem("Item 3"));
         checklist.Items.Add(new ListItem("Item 4"));
         checklist.Items.Add(new ListItem("Item 5"));
         checklist.Items.Add(new ListItem("Item 6"));

         // Manually register the event-handling method for the 
         // SelectedIndexChanged event.
         checklist.SelectedIndexChanged += new EventHandler(this.Check_Clicked);

         // Add the control to the Controls collection of the 
         // PlaceHolder control.
         Place.Controls.Add(checklist);

      }

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3> CheckBoxList Constructor Example </h3>

      Select items from the CheckBoxList.

      <br /><br />

      <asp:PlaceHolder id="Place" runat="server"/>

      <br /><br />

      <asp:label id="Message" runat="server"/>

   </form>

</body>

</html>


Sembra l'esempio giusto, tranne che per le parti di codice non C# all' inizio ed alla fine, forse da eliminare,non saprei veramente, ma a parte questo, la mia domanda è, dove e come devo inserire i nomi nelle mie checkboxs ?

Forse cosi'?
// Populate the CheckBoxList control.
         checklist.Items.Add(new ListItem("checkbox_MySwap.checked"));
         checklist.Items.Add(new ListItem("checkbox_FXswitch.checked"));
         checklist.Items.Add(new ListItem("checkbox_Mypiktur.checked"));
         checklist.Items.Add(new ListItem("checkbox_Capcap.checked"));
         checklist.Items.Add(new ListItem("checkbox_Trimsony.checked"));
         checklist.Items.Add(new ListItem("Item 6"));


nel caso sbagliassi, potrei sapere come fare ?

Ringrazio anticipatamente per l'aiuto.
Ciaoo!!!
aaa
13/03/14 17:04
TheDarkJuster
Quello che hai trovato è ASP.NET e serve per il web non per programmi PC
aaa
20/03/14 3:17
fusebyte
Quindi come posso inserire le mie checkbox in una checkboxlist? ( o altro oggetto con menu' a scomparsa se piu' adatto).

Forse quello che mi serve è
DropDownCheckBoxes o
DropDown CheckBoxList control o
ContextMenuStrip

davvero sono confuso su come creare un menu a tendina con le checkboxs.


Mi basta un piccolissimo esempio se possibile per il C#

Grazie Mille
Ciao
Ultima modifica effettuata da fusebyte 21/03/14 16:49
aaa
25/03/14 20:58
fusebyte
Nessuno .. nessuno che possa darmi un consiglio su cosa fare?

Grazie,Ciao
aaa