custom web user control and web form

Guys,

         I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.

 

/**************************DataSource Class****************************/

 

public class DataSource {

/// <summary>

/// This is to identify unique elements from the markup

/// </summary>

protected string _ID;

/// <summary>

/// This will be the Datasource ID either XML file or the DataTable

/// </summary>

protected object_name;

/// <summary>

/// This property is for the Sequence of the DataSource ID's

/// </summary>

protected int _sequence;

private TypeConverter instance=TypeDescriptor.GetConverter(new object());

public DataSource(){

 

}

public string ID{

get{

return _ID;

}

set{_ID = value;

}

}

public object Name{

get{

return _name;

}

set{_name =value;

 

}

}

 

 

 

public int Sequence{

get{

return _sequence;

}

set{_sequence = value;

}

}

}//end DataSource

 

/********************************************DataSourceCollection Object*******************************/

public class DataSources : CollectionBase {public DataSources(){

}

/// <summary>

/// Summary: Gets an System.Collections.ArrayList containing the list of elements in the System.Collections.CollectionBase instance. Returns: An System.Collections.ArrayList representing the System.Collections.CollectionBase instance itself.Retrieving the value of this property is an O(1) operation.

/// </summary>

 

public void Add(DataSource item)

{

InnerList.Add(item);

}

public DataSource this[int index]

{

get { return (DataSource) InnerList[index]; }set { InnerList[index] = value; }

}

public void AddAt(int index, DataSource item)

{

InnerList.Insert(index, item);

 

}

public void Sort()

{

InnerList.Sort(
new DataSourceComparer());

}

 

}//end DataSources

public class DataSourceComparer: IComparer

{

public int Compare(object x,object y)

{

DataSource s1= (DataSource) x;

DataSource s2= (DataSource)y;

return s1.Sequence.CompareTo(s2.Sequence);

}

}

/************************************ContextMenu*************************/

[ParseChildren(true, "DataSources")]

[DefaultProperty("DataSources")]

public class ContextMenu : WebControl, INamingContainer {

/// <summary>

/// Collection of the Datasources from the markup

/// </summary>

protected DataSources _dataSources;

/// <summary>

/// CssClass for the ASP:Image control

/// </summary>

protected string _menuImageCssClass;

/// <summary>

/// CssClass for the ASP:HyperLink Control

/// </summary>

protected string _menuTextCssClass;public ContextMenu(){

}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

//[Editor(typeof(ContextMenuItemCollectionEditor), typeof(UITypeEditor))]

[PersistenceMode(PersistenceMode.InnerProperty)]

[TypeConverter(
typeof(DataSource))]

[Description("Gets the collection of the menu items")]

public DataSources DataSources{

get{

if(_dataSources==null)

{

_dataSources=
new DataSources();

}

return _dataSources;

}

set{_dataSources = value;

}

}

public string MenuImageCssClass{

get{

return _menuImageCssClass;

}

set{_menuImageCssClass = value;

}

}

public string MenuTextCssClass{

get{

return _menuTextCssClass;

}

set{_menuTextCssClass = value;

}

}

 

 

I haven't included the render method. To keep it short the problem is when i declare the values in the .aspx page as

<cc1:ContextMenu ID="ContextMenu1" runat="server" >

<cc1:DataSource ID="vamsi" Name=S Sequence=1 />

</cc1:ContextMenu>

            .net throws me an error and it says that string could not be converted in to object. My design should take either xml file or data table from the markup and then process either datatables or xml file and extract our own custom data.

 

thanks

vamsi


 

 

0
vamsikomarneni
2/4/2008 8:33:18 PM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 1 Replies
👁️‍🗨️ 1458 Views

vamsikomarneni:
public DataSources DataSources
 

Hi vamsikomarneni,

Base on my experience, there are some error in your code.

See the above line, you can not defined a DataSources like that, this is just one error, maybe there are other error in your code.

Please double check your code, if you still can not solve your problem, let me know. Smile

Thanks. 

Hope it helps,

Hong Gang
 


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
2/6/2008 7:29:58 AM
Reply: