Changing the binding of a template column

R

Rob Edwards

I have a datagrid that is bound to different datasources.

The datagrid contains a templated column (dropdown list).

How do I change the selectedvalue binding to the different datasources? I
can do this at design time by changing the datasource of the grid, going
into the databindings popup and adjusted the selected item there... but I
want to be able to do this in code depending on the dataset selected.

Thanks in advance.
 
J

Jacob Yang [MSFT]

Hi Rob,

I have reviewed your issue. Due to the nature of your issue I need to do
additional research to determine the best way to provide assistance. I will
contact you as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jacob Yang [MSFT]

Hi Rob,

If I didn't misunderstand you, you want to change the databinding
properties on the dropdownlist control that is embedded into a Datagrid as
a template column.

If it is the case, we can hook certain event of the datagrid. In such an
event, we can get an reference to the embedded dropdownlist control and do
what we want against the control. For example, here is a sample, which
hooks the ItemCreated event of the datagrid control. In this event, we use
the FindControl method to locate the dropdownlist control and then bind it
to an ArrayList object.

Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated
Dim DropList As DropDownList =
CType(e.Item.Cells(0).FindControl("DropDownList1"), DropDownList)
If (Not DropList Is Nothing) Then
If Not IsPostBack Then
Dim myList As New ArrayList()
myList.Add("Item 1")
myList.Add("Item 2")
myList.Add("Item 3")
myList.Add("Item 4")
myList.Add("Item 5")
DropList.DataSource = myList
DropList.DataBind()
End If
End If
End Sub
End Class

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top