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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox event handler not working 1

Status
Not open for further replies.

Gill1978

Programmer
Joined
Jun 12, 2001
Messages
277
Location
GB
Hi,

I got a list of checkbox's that when the user selects/ deselects them the OnSelectedIndexChanged is fired and the value of the checkbox(s) should be copied into the listbox.

However the eventhandler isn't being triggered.

This is what I have so far:

aspx page:
Code:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Questionnaire.aspx.cs" Inherits="Questionnaire" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CandlesPlaceHolder" Runat="Server">
    <asp:CheckBoxList ID="CheckBoxList1" runat="server"  OnSelectedIndexChanged="CheckBoxList1_CheckedChanged" >
        <asp:ListItem Text="Presentation 1" Value="V:/projects/JG/PitchBook/PitchBook/Presentations/Test1.ppt"></asp:ListItem>
    </asp:CheckBoxList>
    <asp:CheckBoxList ID="CheckBoxList2" runat="server">
        <asp:ListItem Text="Presentation 2" Value="V:/projects/JG/PitchBook/PitchBook/Presentations/Test2.ppt"></asp:ListItem>
    </asp:CheckBoxList>
    <asp:ListBox ID="FileSelectedListBox" runat="server"></asp:ListBox>
    
</asp:Content>

cs file:
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Questionnaire : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void CheckBoxList1_CheckedChanged(object sender, EventArgs e)
    {
        //ListItem litem;
        //litem.Value = this.Items(
        object i;
        FileSelectedListBox.Text = "<p>Selected Items(s):</p>";
        for (int i = 0; i <= CheckBoxList1.Items.Count - 1; i++)

            if (CheckBoxList1.Items(i).Selected)
            {
                FileSelectedListBox.Text += CheckBoxList1.Items(i).Text + "<br />";
            }
        
        //FileSelectedListBox.Items.Add(CheckBoxList1.Text);
    }
}

Any help would be much appreciated...

Thanks

J
 
sorry being particularly slow today ...
The Item attribute was missing so now:
!FileSelectedListBox.Items.Contains(item))


Thanks for the speedy reply

J
 
Hiya,

Got a question about the above how do I pass the listbox collection to another function as maybe an array?

I've got a merge function which will be inside of a button click event - though so far it's using and open dialogue box to select the files ?

Thanks Jason

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PowerPoint = Microsoft.Office.Interop.PowerPoint; // Add a reference to Microsoft.Office.Interop.PowerPoint.dll
using Office = Microsoft.Office.Core; // Add a reference to office.dll
namespace PowerPointCombine
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Presentations (*.ppt)|*.ppt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = true;
            openFileDialog1.Title = "Select Presentations To Merge";
            openFileDialog1.ShowDialog();
            // Create an instance of PowerPoint, make it visible, and open a new pres.
            PowerPoint.ApplicationClass ppApp = new PowerPoint.ApplicationClass();
            ppApp.Visible = Office.MsoTriState.msoTrue;
            PowerPoint.Presentations ppSet = ppApp.Presentations;
            PowerPoint.Presentation ppMergedPres = ppSet.Add(Office.MsoTriState.msoTrue);
            PowerPoint.Slides ppMergedSlides = ppMergedPres.Slides;
            PowerPoint.DocumentWindows ppWindows = ppMergedPres.Windows;
            PowerPoint.DocumentWindow ppWindow = ppWindows[1];
            PowerPoint.View ppMergedView = ppWindow.View;
            PowerPoint.Presentation ppPres = null;
            PowerPoint.Slides ppSlides = null;
            foreach (string f in openFileDialog1.FileNames)
            {
                //ppSlides.InsertFromFile(f, ppSlides.Count, 1, 999);
                ppPres = ppSet.Open(f, Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
                ppSlides = ppPres.Slides;
                for (int i=ppSlides.Count; i>=1; i--)
                {
                    ppSlides[i].Copy();
                    ppMergedView.Paste();
                }
                ppPres.Close();
            }
            ppMergedPres.SaveAs(@"C:\Documents and Settings\Sam\My Documents\Merged.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
            ppMergedPres.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComO  bject(ppMergedPres);
            ppMergedPres = null;
            System.Runtime.InteropServices.Marshal.ReleaseComO  bject(ppSlides);
            ppSlides = null;
            System.Runtime.InteropServices.Marshal.ReleaseComO  bject(ppSet);
            ppSet = null;
            ppApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComO  bject(ppApp);
            ppApp = null;
        }
    }
}
 
to answer your question:
Code:
protected void SomeEvent(...)
{
   //get selected values
   List<string> selected = new List<string>();
   foreach(ListItem item in myControl.Items)
   {
        if(item.selected)
        {
            selected.Add(item.Value);
        }
   }
   //call function
   MyClass c = new MyClass(...);
   c.MyFunction(selected.ToArray());
}

side points:
1. this post started as a web forms problems, but your last post contains windows forms code (either way the solution is the same)
This usually represents a new problem which should be entered as a new thread instead of highjacking an existing one.

2. getting an array of selected values is totally different than the problem represented in the original post.
This should be entered as a new thread instead of highjacking an existing one.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hiya sorry about that ...

I'll remember that in future ...

Thanks for the help again!!!

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top