• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

How to set MyDataSource property of a Server Control?

I have a server control inherited from CompositeControl. It has a grid and I want to set the grid's data source property from the Property Window. The datasource is one of the SqlDataSources on a page.
0f I use a syntax like;

        [Bindable(true)]
        [Category("Ayarlar")]
        [DefaultValue("")]
        [Localizable(true)]
        public virtual SqlDataSource DataSource
        {
            get
            {
                return (SqlDataSource)ViewState["DataSource"];
            }

            set
            {
                ViewState["DataSource"] = value;
            }
        }
I can set the DataSource but got that error at design time;
"Cannot create an object of type 'System.Web.UI.WebControls.SqlDataSource' from its string representation 'SqlDataSource1' for the 'Database' property"

I'm using ASP.Net with C# if necessary.
Thanks,
0
kosturdur
Asked:
kosturdur
1 Solution
 
Edwin_CCommented:
SqlDataSource is a control and I think it is not a good idea to save the reference of a control in a property.  Instead it is better to store the ID of the control and then get the reference to it when needed.  This is what you find in other standard controls like gridview.  You assign the ID of an exsiting SQLDataSource control in the gridview's datasourceID property but not the datasource property in the designer.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now