473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How can you filter data in a Custom DropDownList....

when the value that determines the filter is databound??

I am trying to make a DropDownList for a set of data that I use a lot
throughout my project. So I extended the DropDownList to retrieve
from the database a set of data to populate the itself with.

Now to make this control as reusable as possible I also added a new
property to this Custom DropDownList. With the goal being that this
property would be used with the DataView RowFilter method to filter
the data.

The problem I have run into is that if I try to bind data to this new
property then the list will not get filtered. If I just set the value
in the HTML tag it works fine. But binding a value (via <%#
container.dataitem("MyField")%>) or setting one in the pages
codebehind (via MyDLL.MyProp = "Test") results in the DropDownList
data not being filtered.

I know this is because the lifecycle and the order in which events are
fired, with the DropDownList being populated during the OnInit event.

I had tried doing something like having a method to retrieve the data
fire during the PreRender event. This results in
"System.NullReferenceException: Object variable or With block variable
not set" error being thrown, which I guess is because PreRender is
after the DataBind event??

So my question is, how can I filter this Custom DropDownList's data??
Is there any way to bind the data during another phase of the
lifecycle?? Or is there a way to filter the list after it has been
populated??

Any help would be most appreciated.

Custom DDL Code included:

<DefaultProperty("ItemType"), ToolboxData("<{0}:ItemsDDL
runat=server></{0}:ItemsDDL>")> Public Class ItemsDDL
Inherits System.Web.UI.WebControls.DropDownList

Private _Itemtype As String = "all"
Private DS As DataSet
Private DV As DataView

<Bindable(True), Category("Data"), Description("The Item's
Arch-type"), DefaultValue("all")> Property [ItemType]() As String
Get
Return _Itemtype
End Get
Set(ByVal Value As String)
_Itemtype = Value
End Set
End Property

Protected Overrides Sub OnInit(ByVal e As EventArgs)
Dim DbRefs As New DbRefsWS.refservice
DS = New DataSet
DV = New DataView(DS.Tables("ItemRef"))

If ItemType <> "all" Then
DV.RowFilter = "ItemType = '" & ItemType & "'"
End If

DataSource = DV
DataTextField = "ItemName"
DataValueField = "ItemID"
DataBind()

MyBase.OnInit(e)
End Sub

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
MyBase.Render(output)
End Sub

End Class
Nov 18 '05 #1
0 2494

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in...
4
by: Keith | last post by:
A2003, XP Pro. I'm in the middle of designing a form to act as a custom filter, like a very basic 'filter by form'. It has two sets of combos, those on the left are to choose the field name(s)...
2
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
1
by: Stanley | last post by:
Hello all, I have a custom collection that I am using to fill a DropDown list that I need to filter out items based on another dropdown list. My problem is the actual filter in the collection. I...
3
by: Juanjo | last post by:
I have a datagrid with two temnplate columns. When a row is in edit mode the each template columns show a dropdownlist (its datasource is a dataview). I need to filter data of second dropdownlist...
2
by: renatois | last post by:
DropDownList with custom Data Display in a GridView Hi all, I have a GridView that has a STATUS template field showing a DropDownList on Edit Mode with the users status that can be C, I, B, E. ...
5
by: Jim Mandala | last post by:
Using Access 2003 front end; SQL Server 2005 Back end: I have a complex form that has lots of data fields including about thirty or so checkboxes storing Yes/No data that I would like my users...
8
by: Cirene | last post by:
I have a dropdownlist that is bound to a query. Is it possible to further filter the items after the fact? The dropdownlist is inside a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.