Casting

  • Thread starter Thread starter Ian Frawley
  • Start date Start date
I

Ian Frawley

Hi all,

Can anyone help me please.

I have the following code that is recieves a list of controls, creates them
dynamically and adds them to a table. What I need to do is figure out
whether the object I have created has an avaible data source. As I create
the objects as type System.Web.UI.Control they don't by default have a
DataSource property so I am a bit purplexed as what to do.

/******* Code *******/
ActionsWebService.Actions actionsweb = new ActionsWebService.Actions();
ActionsWebService.ActionObjects objects =
actionsweb.GetActionObjects(ActionID);
foreach(ActionsWebService.ActionObjects.ObjectsRow row in objects.Objects)
{
Type type = Type.GetType("System.Web.UI.WebControls." + row.ObjectType +
", System.Web,Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a");
System.Web.UI.Control temp =
(System.Web.UI.Control)Activator.CreateInstance(type);
ActionsWebService.ActionObjectConfigSettings actionconfig =
actionsweb.GetActionConfigSettings(row.FriendlyName);

/*IMPORTANT BIT!!!!! WHAT I NEED TO BE ABLE TO DO IS IDENTIFY IF THE
OBJECT REQUIRES A DATA SOURCE
OR NOT AND THEN CAST IT TO THE REQUIRED OBJECT*/
if(temp.GetType().FullName == "TextBox")
temp.ID = actionconfig.Settings.IDColumn.ToString();
else
{
temp.ID = row.FriendlyName;
(( WHAT OBJECT SHOULD I USE )temp).DataSource =
actionconfig.Settings;
(( WHAT OBJECT SHOULD I USE )temp).DataValueField =
actionconfig.Settings.IDColumn.ToString();
(( WHAT OBJECT SHOULD I USE )temp).DataTextField =
actionconfig.Settings.NameColumn.ToString();
}
TableRow tr = new TableRow();
TableCell tcObject = new TableCell();
tcObject.Controls.Add(temp);
TableCell tcObjectDescription = new TableCell();
tcObjectDescription.Text = row.FriendlyName.ToString();
tr.Cells.Add(tcObject);
tr.Cells.Add(tcObjectDescription);
controlsTable.Rows.Add(tr);
}
Page.DataBind();
/******************************/

Does this make sence

Cheers
 
Back
Top