13/03/14 9:06
fusebyte
Ho scritto delle funzioni usando delle checkbox per controllarle ,per es:
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:
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'?
nel caso sbagliassi, potrei sapere come fare ?
Ringrazio anticipatamente per l'aiuto.
Ciaoo!!!
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