on 03-10-2005 7:08 PM
Can someone please post a code snippet on how to bind data to a DropDownByKey control? Thanks.
Peter
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.