cancel
Showing results for 
Search instead for 
Did you mean: 

Complex DataBinding

Former Member
0 Kudos

Can someone please post a code snippet on how to bind data to a DropDownByKey control? Thanks.

Peter

Accepted Solutions (1)

Accepted Solutions (1)

reiner_hille-doering
Active Contributor
0 Kudos

If you know your datasource at design time, just put it onto your page or in your code-behind. In most of these cases you just use the desigt-time feature to set DataSource, DataMember and the binding fields of the ItemTemplate. The result is something like this:

<sap:DropDownByKey id=DropDownByKey1 runat="server" DataMember="Tab" DataSource="<%# sapProxy11 %>">

<sap:DropDownListItem ID="DropDownByKey1_ItemTemplate" Key='<%# DataBinder.Eval(target.DataSourceRow.DataItem, "Funcname") %>' Text='<%# DataBinder.Eval(target.DataSourceRow.DataItem, "Funcname") %>'>

</sap:DropDownListItem>

</sap:DropDownByKey></P>

If your datasource is e.g. an array in your code-behind, you can create such a snipped by hand.

If the datasource is NOT know at design-time, you can databind, but you need to control databinding using the ItemCreated and ItemDatabound events. Or you don't use databinding and just write some code that iterates over your datasource and fills the Items collection of the DropDownByKey.

This is in contrast to Microsoft's controls, because we compiling for databinding and they use reflection.

Message was edited by: Reiner Hille-Doering

reiner_hille-doering
Active Contributor
0 Kudos

I have just seen that Ofer has written a really nice article that describes the differences between our databinding and Microsoft's, together with other differences. Congratulation Ofer!

Here it is:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/sap netweaver .net controls vs. asp.net controls.pdf

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

One remark I'd like to add to Reiner's answer:

In case the datasource is not known in design time you can still use data binding... but not in an easy way. You have to add code in the "ItemDataBound" event of the drop down to "tie" things together. But as Reiner said, maybe it will be simpler in this case to fill the dropdown with the "add" function of the items property.

Regards,

Ofer