This is a migrated thread and some comments may be shown as answers.

Help needed on finding a control in a grid edit form

2 Answers 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 1
Andy Green asked on 21 May 2010, 10:54 AM
Hi

I have an EditFormTemplate and in the FormTemplate I have 2 dropdowns (They are asp:dropdowns, not Rad ones) I can populate them with data from code behind but what I want to do is populate the second ddlist from a value from the first.

This is the first ddl markup

<

 

asp:DropDownList ID="ddlSite" runat="server" AutoPostBack="true" SelectedIndexChanged="UpdateLocation"></asp:DropDownList>

On ther server I get the UpdateLocation event

 

    Protected Sub UpdateLocation(ByVal sender As Object, ByVal e As System.EventArgs)  
 
 
        Dim ddlLocation As DropDownList = DirectCast(FindControl("ddlLocation"), DropDownList)  
        Dim mw As New CoreData  
        Dim mw_dt As DataTable = mw.LocationByParent(sender.selectedvalue)  
        If mw_dt.Rows.Count > 0 Then  
            With ddlLocation  
                .Items.Add(New ListItem("", 0))  
                .DataSource = mw_dt 
                .DataValueField = "LocationId" 
                .DataTextField = "LocationName" 
            End With  
        End If  
 
    End Sub 
The problem is that the value for the second dropdownlist is always nothingm the findcontrol is failing.

I have also tried the following to find the control:

 

Dim editedItem As GridEditableItem = CType(CType(sender, DropDownList).NamingContainer, GridEditableItem)

 

 

Dim ddlLocationt As DropDownList = CType(editedItem("ddlLocation").Controls(0), DropDownList)

 

 

How do I get a handle on the second DropdownList?

Andy

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 May 2010, 11:30 AM
Hello,

You can access the second DropDownList using the NamingContainer property after getting reference to the first DropDownList. Here is an example.

VB:
 
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As ObjectByVal e As EventArgs) 
    Dim dropDown As DropDownList = DirectCast(sender, DropDownList) 
    Dim editForm As GridEditFormItem = DirectCast(dropDown.NamingContainer, GridEditFormItem) 
    Dim secondDropdown As DropDownList = DirectCast(editForm.FindControl("DropDownList2"), DropDownList) 
    secondDropdown.Enabled = False 
End Sub 


-Shinu.
0
Andy Green
Top achievements
Rank 1
answered on 21 May 2010, 02:56 PM
Thanks Shinu

Andy
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Andy Green
Top achievements
Rank 1
Share this question
or