Help or suggestion to build a list of values control


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Help or suggestion to build a list of values control

Threaded View

  1. #1
    Join Date
    Oct 2005
    Location
    Auckland NZ
    Posts
    2

    Help or suggestion to build a list of values control

    Hi all, Ill do my best to explain as best I can.


    I'm trying to build a list of values from which a user can select either individual list items or multiple. (See attachments)
    The control currently consists of a drop down list and an hyperlink. If the user is to select an individual item then it is simply a matter of binding the values to the drop down list and the hyperlink is disabled and not visible. However if the user may select multiple items you cannot do it with the conventional drop down list, it will be a list box. In this case the hyperlink is enabled and visible, when clicked on opens up a new window via javascript, the window opened is determined by the height and width set in the control tag. Usually only 350 x 250.

    This window has two forms, the first has a text box and beside it a submit/search button, which I want to display if the control tag in the other window has the attribute Search set to true. Upon a user clicking the search button it fills the list box, which is in the second form, with values that match the criteria. The second form also has a submit button. The user will select these items as necessary and click the submit button this will send the select items back to the drop down list in the parent window and close the popup window.

    The reason I'm doing it this way is to save space, as I will be having this control multiple times on the same page. I just need to find a way of getting the control attributes/properties to the popup without a huge ugly querystring, surely there has got to be a cleaner way to do this. Following is some of the code. I have also placed a couple of screen shots on my website http://geocities.com/illcomms/ these were done when I was using ASP and now wanting something similar in .Net.

    Project.aspx (The page which calls the control)
    <%@ Register TagPrefix="it" TagName="Listing" Src="~/UserControls/Listing.ascx"/>
    <form id="frmProjectSearchCriteria" runat="server">
    <table class="contentTableShort">
    <tr>
    <td>
    <table style="WIDTH:100%">
    <tr>
    <td nowrap>
    <asp:Label id="lblTrialMenu" EnableViewState="true" Text="<u>T</u>ask Status Trial:" Runat="Server" />
    </td>
    <td>
    </td>
    <td>
    <it:Listing id="ddlListing1" MultipleSelection="True" MultipleLine="False" Search="True" WindowSizeHeight="350" WindowSizeWidth="250" WindowTitle="ProjectStatus" Runat="Server" />
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>

    Listing.ascx (The control itself)
    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="Listing.ascx.cs" Inherits="Projects.Listing" %>
    <aspropDownList ID="ddlMainListing" style="width:200px;" Runat="Server"/>
    <asp:image id="imgShowList" style="vertical-align:middle;" Runat="server" ImageUrl="../images/dropDownUp.jpg" AlternateText="Select"/>

    Listing.ascx.cs (The controls code behind)

    namespace Projects
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    public class Listing : System.Web.UI.UserControl
    {
    protected System.Web.UI.WebControls.DropDownList ddlMainListing;
    protected System.Web.UI.WebControls.Image imgShowList;

    #region Web Form Designer generated code

    override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    }


    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);
    }

    #endregion

    public bool _MultipleSelection;
    public bool _MultipleLine;
    public bool _Search;
    public int _WindowSizeHeight;
    public int _WindowSizeWidth;
    public string _WindowTitle;

    public bool MultipleSelection
    {
    get { return _MultipleSelection; }
    set { _MultipleSelection = value; }
    }

    public bool MultipleLine
    {
    get { return _MultipleLine; }
    set { _MultipleLine = value; }
    }

    public bool Search
    {
    get { return _Search; }
    set { _Search = value; }
    }

    public int WindowSizeHeight
    {
    get { return _WindowSizeHeight; }
    set { _WindowSizeHeight = value; }
    }

    public int WindowSizeWidth
    {
    get { return _WindowSizeWidth; }
    set { _WindowSizeWidth = value; }
    }

    public string WindowTitle
    {
    get { return _WindowTitle; }
    set { _WindowTitle = value; }
    }

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (MultipleSelection == true)
    {
    string scriptStr = "window.open('" + Page.ResolveUrl("~/UserControls/Menu.aspx") + "','" + WindowTitle + "','height=" + WindowSizeHeight + ",width=" + WindowSizeWidth + ",screenX=400,screenY=400,top=400,left=400,location=no,menubar=no,resizable=yes,scrollbars =no,status=no,toolbar=no')";

    imgShowList.Attributes.Add("onclick", scriptStr);
    }
    else
    {
    //This is where if single selection is done, where binding of data is done straight to the drop down list.
    }
    }
    }
    }

    Menu.aspx (This page popups when imgShowList is clicked)
    <form runat="server" ID="Form1">
    <asp:Table BorderWidth="0" CellPadding="1" CellSpacing="0" Width="100%">
    <asp:TableRow>
    <asp:TableCell>
    <asp:TextBox id="txtSearch" Visible="False" tabindex="1" accesskey="U" runat="Server" Width="65%" />
    <asp:Button id="btnSearch" Visible="False" CssClass="smallbtn" Text="Search" runat="server" Width="34%" />
    </asp:TableCell>
    </asp:TableRow>
    </form>
    <form runat="server" ID="Form2">
    <asp:TableRow>
    <asp:TableCell>
    <aspropDownList ID="ddlMenuListing" Visible="False" runat="server" multiple="true" style="height:120;width:100%;"/>
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow>
    <asp:TableCell>
    <asp:Button ID="btnSelectClose" Visible="False" CssClass="smallbtn" Text="Select and Close" Runat="server" Width="100%"/>
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>
    </form>

    Menu.aspx.cs (code behind)
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    namespace Projects.ControlPage
    {
    public class ControlPage : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox txtSearch;
    protected System.Web.UI.WebControls.Button btnSearch;
    protected System.Web.UI.WebControls.DropDownList ddlMenuListing;
    protected System.Web.UI.WebControls.Button btnSelectClose;

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    }

    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion

    private void Page_Load(object sender, System.EventArgs e)
    {
    // This is where I need to find out if Search is enabled
    // on the control.
    // one other thing that I will add later is the stored procedure which it is to call
    if (Search == true)
    {
    //These are disabled by default
    txtSearch.Visible = true;
    txtSearch.Enabled = true;
    btnSearch.Visible = true;
    btnSearch.Enabled = true;
    }
    }
    }
    }
    Attached Images Attached Images

Similar Threads

  1. Replies: 4
    Last Post: 12-08-2002, 12:56 PM
  2. Replies: 6
    Last Post: 04-15-2002, 03:05 PM
  3. Using List box with VB6 Data Grid control
    By Carl in forum VB Classic
    Replies: 1
    Last Post: 08-23-2001, 08:04 AM
  4. Data List & ADO Data Control
    By Chris cherryholmes in forum VB Classic
    Replies: 1
    Last Post: 07-09-2000, 01:47 AM
  5. Replies: 9
    Last Post: 06-20-2000, 05:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center