Click here to Skip to main content
Email Password   helpLost your password?

Introduction

There are many dropdown controls out there for the web, but I have not seen any dropdown controls which can show multiple columns like in VB or MS Access, so I thought of building my own control, which will display the columns based on the selection made in a SQL statement, e.g., "Select col1,col2,col3 from db", but I recommend to select two or three columns, at most.

How the control was built

This is not just one control, but it's a composite control, means it's built using more than one control, resulting in one super control. The figure below demonstrates how the control works. The controls used are TextBox, Label, DataGrid and a Panel control which holds all the controls. I have also set the ID property for the TextBox and the DataGrid as "txt" and "DDL", because due to the implementation of the INamingContainer interface (to maintain unique names for the controls), the control would have generated ":CTL1", if I did not set the ID value.

Using the code

It's very simple to use the code, I have shown this sample in VB.NET, but you could use it in C# also. Download the DLL file for this control, and just add the control to your toolbox by selecting the DLL from the location where you unzipped the file. Once you drop the control in your aspx page, you could set the properties either through the Properties window, or from the HTML page.

Properties for the Control

There are many properties for this control which are self explanatory, but there are some properties which need some explanation, like:

One more thing, there is one method for this control, "retTotRows", you have to use this method, else control may not work properly. Actually, this method returns the count of rows to be populated in the dropdown list, and generates the Click event.

To use this method:

MultiColDD_List1.retTotRows(DS_P.Tables(0).Rows.Count)

or if you are generating the items from any other means, make sure you pass the total rows to this method.

  Private Sub Page_Load(ByVal sender As System.Object, 
   ByVal e As System.EventArgs) Handles MyBase.Load
   If Not IsPostBack Then

    MultiColDD_List1.Width = Unit.Pixel(300)
    MultiColDD_List1.Height = Unit.Pixel(200) ' make sure you set 

     'the height property, else there will be no scroll bar.

    MultiColDD_List1.DataSource = CreateDataSources() 
     ' this function returns the dataset to bind to the control

    MultiColDD_List1.DataBind()

   End If

  End Sub
   
  Function CreateDataSources() As DataSet
   Try
    Dim DS_P As DataSet
    Dim cn As SqlConnection

    Dim cmdP As SqlDataAdapter

    Dim sqlStr As String = 
     "select au_Lname,Phone from authors " '  you could add more cols


    'Change the SQL Server name {Data Source = <your server name>}

    cn = New SqlConnection("Integrated Security=SSPI;Persist Security 
     Info=False;Initial Catalog=Pubs;Data Source=NJ5Mail")
    cmdP = New SqlDataAdapter(sqlStr, cn)

    DS_P = New DataSet

    cmdP.Fill(DS_P, "Policies")
    MultiColDD_List1.retTotRows(DS_P.Tables(0).Rows.Count) 
     ' make sure you use this method

    Return DS_P


    DS_P.Dispose()
    cmdP.Dispose()
    cn.Close()

   Catch ex As Exception

   End Try
  End Function

Retrieving Control Value

Once you select the item, the value for the dropdown could be retrieved either using JavaScript to send it to another page or directly in the code behind. Suppose we have an HTML button. In the onClick event of this button, the value of the dropdown could be sent to another page, the code below demonstrates this:

<script language="javascript">

function Show(){
  window.open("anotherPage.aspx?ddValue=" + 
    document.getElementById('MultiColDD_List1_txt').value);
}
</script>
<input id="Shows" onclick="Show();" type="button" value="HTML BUTTON">

Make sure that the name of the control ends with "_txt". To use it in the same page, directly call the control's value like: MultiColDD_List1.Text.

Using the Intellisense

There are many custom controls, when you use them in your aspx page, you don't get to see the properties for the control, which makes your life difficult finding the properties for the control. So how to make the intellisense work? First, you have to generate the schema file for this control, i.e., ".xsd", the ZIP file contains the .xsd for this control. Copy this .xsd file to the following folder:

and in the body tag of your aspx page, add the following code:

<body xmlns:ksj1="urn:http://schemas.ksjControls.com/ASPNET" 
                                    MS_POSITIONING="GridLayout">

The figure below shows the intellisense:

Points of Interest

This control implements the INamingContainer interface. If you see the HTML output of your ASP.NET pages, the client-side names of the controls don't always match the names you've given them in the server code. This is because ASP.NET automatically renames them to keep things organized, and to ensure that no two controls have the same client-side ID. By implementing the INamingContainer interface, the custom control is identified as a container for the child controls. It also ensures that all the sub-controls are named similarly in the output. This will be important for referencing the controls in client-side code. That's why when you click the Show button, the value of the control is taken from MultiColDD_List1_txt.value and not from the ID you have given in the aspx page, i.e., MultiColDD_List1. Because this is a composite control, instead of using the Render method, I have overridden the CreateChildControls method, and all the tricks are done here. Another feature of this control is that when you move the mouse over the grid, you can see the text changing in the textbox.

Enjoy..

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Rantnot satisfied
vpg1986
4:31 13 Jan '10  
the tool not as good as it is claimed
and even no code for the tool is provided
we R on "CODE"Project.com
plz post the code here
GeneralMy vote of 1
TAFIN
18:19 21 Dec '09  
fuck
GeneralMultiColDD_List in C#
Nitish.1127
21:12 21 Jun '09  
Can u send me the same control bug free demo of the MultiColDD_List I have a error on this control MultiColDD_List_DLL is Undefine..

please send me the full demo in c#.


thanks in advance..

please forwarded into my mail id

nit1127@hotmail.com

.aspx page code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4"%>
<%@ Register Assembly="multiColDD_List" Namespace="multiColDD_List" TagPrefix="ksj">
<!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>Untitled Page</title>
<style lang="text/css" media="screen" type="text/css">
.general
{
FONT-SIZE: 8pt;
COLOR: navy;
FONT-FAMILY: Verdana, Arial, helvetica, sans-serif
}
</style>

</head>
<body xmlns:ksj1="urn:http://schemas.ksjControls.com/ASPNET">
      <form id="form1" runat="server">
            <asp:Label ID="Label1" runat="server" />
<ksj:multiColDD_List ID="MultiColDD_List1" runat="server" isStateMaintained="true"   SelectedIndex="0" Text="Select"
               ViewColID="8" CssClass="general" GridRowColor="Azure" GridTextColor="Black"/>
      </form>
</body>
</html>

.aspx.cs 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;
using System.Data.SqlClient;

public partial class Default4 : System.Web.UI.Page
{

      protected void Page_Load(object sender, EventArgs e)
      {
            try
            {
                  SqlConnection con = new SqlConnection("Data Source=Project3;Initial Catalog=jobiste;User ID=ok;Password='ok12';");
                  string sql = "select *from Job_Industry";
                  SqlDataAdapter sda = new SqlDataAdapter(sql, con);
                  DataSet ds = new DataSet();
                  sda.Fill(ds);
                  if (ds.Tables[0].Rows.Count &gt; 0)
                  {
                    
                        //MultiColDD_List1.retTotRows(ds.Tables[0].Rows.Count + 1);
                        MultiColDD_List1.Width = Unit.Pixel(200);
                        MultiColDD_List1.Height = Unit.Pixel(200);
                        MultiColDD_List1.DataSource = ds.Tables[0];
                        MultiColDD_List1.DataMember = "IndustryTypeDes";
                        //MultiColDD_List1.
                        MultiColDD_List1.DataBind();
                  }
            }
            catch (Exception ex)
            {
                  Response.Write(ex.Message.ToString());
                  Response.Write(ex.Data.Values.ToString());
                  Response.Write(ex.InnerException.Message.ToString());
                  Response.Write(ex.HelpLink.ToString());
            }
      }
}

NITISH

GeneralNot Working
Bryan Duchesne
11:24 24 Dec '08  
I get a code error in the Javascript. If you have new updated DLLs please send them or post them to this forum. This control would be really great if it only worked. Cry Confused
Generalon page error
sairamvegi
6:11 21 Apr '08  
I have downloaded the dll and added it to my project .
But while executing, when ever i click on drop down it's giving "error on page'.plase proivide the solution and Is their any way to get the code, If possible send to my id.

Thanks and regards
Sairam.V

Sign In·View Thread
GeneralCode is no working with me
nileshmacwan
0:50 21 Apr '08  
I had tried with northwind, but i am geting 6 after text box, and data is not displaying, Bu when i see in with view->Page Source. I can see all data what i want, but no able to view, and not working as shown picture file
GeneralModified Code
sairamvegi
0:32 21 Apr '08  
I have downloaded the dll and added it to my project .
But while executing, when ever i click on drop down it's giving error on page.plase proivide the solution and Is their any way to get the code, If possible send to my id.

Thanks and regards
Sairam.V
GeneralIs their any way to get the code [modified]
dileepdil
21:32 27 Mar '08  
Is their any way to get the code, If possible send to my id

modified on Friday, March 28, 2008 6:29 AM

General"MultiColDD_List1_DDL is undefined"
Maheswari_Ramasamy
20:06 29 Nov '07  

Hi,
when i click on the controls dropdown button in IE it gives this error

Laugh "MultiColDD_List1_DDL is undefined".
can anybody help me to solve the error.....
My mail id is maheswarir85@gmail.com
GeneralRe: "MultiColDD_List1_DDL is undefined"
Amit Chandak
15:59 10 Mar '09  
When I click on n the controls dropdown button in IE it gives this error

"MultiColDD_List1_DDL is undefined".
can anybody help me to solve the error.....
General6 and no result in drop down
Diljeet
8:57 10 Oct '07  
Hi it is Diljeet.
I have downloaded the dll and added it to my project .
But while i am executing it the control.Instead of showing drop down arrow it is showing 6.
And no drop down is populating.while I have given datasource as a data table which is having four rows.
plz tell me where i am wrong.
My email id is jamwalboy2003@yahoo.co.in

Diljeet Singh Jamwal

GeneralRe: 6 and no result in drop down
Dewey
21:55 10 Oct '07  
Was that Diljeet?
GeneralRe: 6 and no result in drop down
Diljeet
5:57 11 Oct '07  
Yes ,Diljeet Singh Jamwal

Diljeet Singh Jamwal

GeneralCan make it work in VStudio 2005 C#
BENETI
22:47 4 Jul '07  
I get an error on page when i click on the control. Please help me???
Dalik_81@yahoo.com
General6 and no rows
DJDAGZ
1:32 29 Mar '07  
Hi Jay

Great tool - i've rewritten it in C# and got all the code working.

But ... instead of a dropdown arrow i am getting a "6", and no rows are showing in the DropDown even though they are in the DataSet

My email is djohnston@linney.com if you have any ideas

Thanks
Dave
GeneralMultiColDD_List1_DDL is undefined
ismail turkmenoglu
7:03 26 Mar '07  
Hi,
when i click on the controls dropdown button in IE it gives this error

"MultiColDD_List1_DDL is undefined".

Please mail me the latest dll on e120358@metu.edu.tr

ismail
QuestionRe: MultiColDD_List1_DDL is undefined
laisinwei
19:04 22 Jul '08  
i had face this same problem, can any one help me ?
QuestionRe: MultiColDD_List1_DDL is undefined
laisinwei
19:05 22 Jul '08  
my email is lysiwe@gmail.com
Generalnot Working In visual Studio 2005, C#
mehnazhassan
21:08 1 Mar '07  
when i click on the controls drop button in IE it gives this error

"MultiColDD_List1_DDL is undefined".

Plz mail me the latest dll on hassanjcp@gmail.com
GeneralRe: not Working In visual Studio 2005, C#
Erichin
21:51 17 Mar '07  
I face the same problem too.. please mail me the latest dll too..
my email is chinjw@hotmail.com
QuestionCode
stockcer
10:34 29 Jan '07  
I am having a difficult time getting this to work with VS2005 and .NET 2.0. Is there any way to get the source code so that I can modify it to work.
QuestionNeed to retrieve values from multiple columns
derwood
13:16 6 Jan '07  
Smile I follow your example to work on the multiple column dropdown for asp.net, and it works. But I have another question. If I have two columns, and ViewColID is set to 0, how to get the value of column 1 of the selected row?

Thanks



gtsai@hns.com
Gan Tsai
QuestionUse the control in Asp.NET 2.0
alanveitch
2:02 8 Sep '06  
Confused Yup, me too.

It looks really neat, but I can't get it to work either.

Have you got an updated version for Framework II?

Regards

Alan



GeneralUse the control in ASP.NET 2.0 [modified]
Kaushik Dutta
1:17 22 Jun '06  
Hi,

This is Kaushik. I tried to implement your control (ASP.NET 2.0) using the demo project code, with little bit modifications..."codebehind" changed to "codefile". But nothing seems to work.

For your reference here are the things I've done:
1. Referred assemblies multiColDD_List.dll & multiColDD_List.DropDowns.dll
2. Draged n dropped the 'MultiColDD_List1' ctrl
3. Used the same code behind.

What I find when the webapp runs
1. A "6" instead of Drop down arrow (in firefox, in ie the image comes)
2. No rows shown in the internal DataGrid i.e. nothing happens when the dropdown selected. Rows, however, are contained in the dataset.

Need your comments on this. Can u provide the control source?

Regards

Kaushik Dutta kdutta_2003#hotmail.com

-- modified at 6:18 Thursday 22nd June, 2006
GeneralRe: Use the control in ASP.NET 2.0 [modified]
PEKESTOEMP
5:44 25 Jul '06  
I also have this same issue...

I cannot make it work Frown
I'm sure it is a really great control,...
I use VS.NET 2005 on ASP.NET 2

Am I missing something?

Suggestions updates can be sent to pekestoemp@hotmail.com.

Thanks

Pekestoemp.


-- modified at 14:00 Tuesday 25th July, 2006


Last Updated 30 Mar 2005 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010