开发者

ASP.NET ObjectDatasource use code-behind property

Is it possible to use a page-property as Datasource/DataSourceID for a ListBox or other controls like a Telerik RadCombobox?

I'm having a issue to bind data to a Telerik RadCombobox defined in a FilterTemplate of a RadGrid. I created a property in the code-behind of my page and want to a开发者_如何学运维ccess it this way.

<telerik:GridBoundColumn [...]>
    <FilterTemplate>
        <telerik:RadComboBox
            ID="filter"
            AutoPostBack="false" 
            AppendDataBoundItems="true" 
            DataSourceID="<%# PropertyInTheCodeBehind %>"
            runat="server" />           

        [...]
    </FilterTemplate>

Or is there another way to accomplish this? I just want to access data in the code-behind.


Rather define a method or an array and pass it to the DataSource property of the combo. Here are a couple of examples:

<telerik:GridBoundColumn [...]>
    <FilterTemplate>
        <telerik:RadComboBox
            ID="filter"
            AutoPostBack="false" 
            AppendDataBoundItems="true" 
            DataSource="<%# (new string[] { "Item1", "Item2", "Item3", "Item4" }) %>"
            runat="server" />           

        [...]
    </FilterTemplate>

<telerik:GridBoundColumn [...]>
    <FilterTemplate>
        <telerik:RadComboBox
            ID="filter"
            AutoPostBack="false" 
            AppendDataBoundItems="true" 
            DataSource="<%# GenerateComboSource() %>"
            runat="server" />           

        [...]
    </FilterTemplate>

public string[] GenerateComboSource()
{
  return (new string[] { "Item1", "Item2", "Item3", "Item4" });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜