LakersOwnBoston
New Member
Hi,<BR><BR> I've got a dropdownlist inside a header template in my data grid window. I give it an id = "ProductList". It is not accessible via Page.FindControls. At least not by that simple name. I noticed in the browser source it's referred to as OrderGrid_ctrl1_ProductList, but that didn't work with FindControls either. What other methods can I use to get to this header control ?<BR><BR> I've discovered that it is not a part of the items collection since it is in the header. I know others use controls in header templates (images & such), so there MUST be some way to access them. <BR><BR>Thanks,<BR>Deanna<BR>header template in your datagrid? or datalist?OK I just tried it as as DropDownlist in the Header of my Datalist, and all I can say is I would like to see an answer to this question as well. Put the DropDownlist within [headertemplate] tags and it becomes invisible to the application, remove it and stand it on it's own and all code works great.Got IT! A very nice MS employee posted an answer on the usenet group. I hope he doesn't mind that I copy it here...<BR><BR>Deanna<BR><BR>================================================== ===========<BR>Hi Deanna,<BR><BR> Its a really good question! There are many ways to get a reference to <BR>controls in the header template. <BR> <BR> 1) Use the FindControl method to directly find the control with its <BR>uniqueID.<BR> Lets say you have your headertemplate in the first column then you <BR>can get your dropdown listbox <BR> by using the FindControl method like this. <BR><BR> mycontrol = DataGrid1.FindControl("_ctl1:headerListbox")<BR><BR> Please note that FindControl method does not recurssively search <BR>for controls. It only searches in the current control level.<BR><BR> 2) If you want to find a control dynamically then you can write your <BR>own findControl function.<BR> <BR> Here is a sample function for you. It will walk down the control <BR>tree and find your control.<BR><BR> Public Function FindMyControl(ByVal c As Control, ByVal s As <BR>String) As Control<BR> Dim i As Integer<BR> Dim found As Control<BR> For i = 0 To c.Controls.Count - 1<BR> If c.Controls(i).UniqueID.EndsWith(s) Then<BR> found = c.Controls(i)<BR> Exit For<BR> Else<BR> found = FindMyControl(c.Controls(i), s)<BR> If Not found Is Nothing Then<BR> Exit For<BR> End If<BR> End If<BR> Next<BR> FindMyControl= found<BR> End Function<BR><BR> Sample call to the above function: <BR><BR> dim mybox as control<BR> mybox = FindMyControl(DataGrid1, "ControlName")<BR><BR> 3) If you want to know which is the current selected item in the <BR>dropdownlist then you can use the following code in the <BR>selectedIndexchanged <BR> event for the listbox.<BR><BR> Protected Sub SelectionChangedForCombo(ByVal sender As Object, <BR>ByVal e As System.EventArgs)<BR> Dim mylist As DropDownList = CType(sender, <BR>DropDownList)<BR> Label1.Text = mylist.SelectedItem.Text <BR> End Sub<BR><BR> Hope this helps.<BR><BR>thanks,<BR>Anand Hegdewow, thanks Deanna.<BR><BR>I'm reaching the conclusion that while .NET makes somethings MUCH MUCH easier than ASP Classic, there are other things that seem needlessly difficult. (Databinder.eval blah blah blah to return a record?!?!) Oh well, once we get past this learning curve, I think it's really going to be wodnerful