|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThere 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., " How the control was builtThis 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 Using the codeIt'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 ControlThere 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, " 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 ValueOnce 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 <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: Using the IntellisenseThere 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 xmlns:ksj1="urn:http://schemas.ksjControls.com/ASPNET"
MS_POSITIONING="GridLayout">
The figure below shows the intellisense: Points of InterestThis control implements the Enjoy..
|
||||||||||||||||||||||