Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Datagrid and Filter capabilities


Message #1 by Imar Spaanjaars <Imar@S...> on Thu, 29 Aug 2002 06:15:00 +0200
Hi there,

I am trying to create a datagrid with in-line filter capabilities with a 
drop down. I have added the drop down to the grid using the ItemCreated 
event like this:

Dim myDropDown As DropDownList = New DropDownList()
myDropDown.ID = "ddFilter"
         ' Add list items and reselect based on view state. Left out
         ' Add item to grid
Dim cellForList As TableCell = CType(e.Item.Controls(1), TableCell)
cellForList.Controls.Add(myDropDown)

This adds the drop down to the second header row of my datagrid. This row 
(a TemplateColumn) also contains the word "Category" as I use this heading 
to sort the grid based on it's caption.

Now my question is: how do I react to the drop down change event (if I set 
AutoPostback=true for example)? I tried to react to the SortCommand, check 
if the source was column "Category" and then filter the grid instead of 
sorting it, but that seems a bit dirty, IM.

I also tried to get to the grids item collection in the Page_Load, but the 
grid only seems to have Items and AlternatingItems and no header. 
Therefore, I can't seem to use FindControl("ddFilter") to find out which 
item was selected in the header.

Am I missing something here? Can I hook up an Event handler to the 
dynamically created drop doen? If so, how does that work in this case?

Thanks in advance for any reaction.


Imar








  Return to Index