G
Guest
Hello EveryBody,
I have a dropdownlist with some values as .net server controls & a button ,
on clicking a button i need to generate the choosen contorl dynamically.
I am giving a small glimpse of my code for your understanding
the aspx page has dropdwon list with values as below.
<aspropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="Label">Label</asp:ListItem>
<asp:ListItem Value="DropDownList">DropDownList</asp:ListItem>
<asp:ListItem Value="DataGrid">DataGrid</asp:ListItem>
<asp:ListItem Value="DataList">DataList</asp:ListItem>
<asp:ListItem Value="CheckBox">CheckBox</asp:ListItem>
<asp:ListItem Value="RadioButton">RadioButton</asp:ListItem>
<asp:ListItem Value="RadioButton">RadioButton</asp:ListItem>
<asp:ListItem Value="Table">Table</asp:ListItem>
<asp:ListItem Value="TextBox">TextBox</asp:ListItem>
<asp:ListItem></asp:ListItem>
</aspropDownList>
now the code that gets executed at the click of the button is as follows
i am using the reflection name space
String strCtrlName = DropDownList1.SelectedItem.Value ;
Response.Write(strCtrlName);
Type tp=System.Type.GetType("System.Web.UI.WebControls."+strCtrlName ,true) ;
Object obj = Activator.CreateInstance(tp0;
PlaceHolder.Controls.Add(new obj );
but i get error at the line " Type
tp=System.Type.GetType("System.Web.UI.WebControls."+strCtrlName ,true) ; "
error below :
System.SystemException: {"Could not load type
System.Web.UI.WebControls.DataGrid from assembly TestingDynamicCtrl,
Version=1.0.1950.28617, Culture=neutral, PublicKeyToken=null."}
AssemblyName: "TestingDynamicCtrl, Version=1.0.1950.28617, Culture=neutral,
PublicKeyToken=null"
ClassName: "System.Web.UI.WebControls.DataGrid"
Message: "Could not load type System.Web.UI.WebControls.DataGrid from
assembly TestingDynamicCtrl, Version=1.0.1950.28617, Culture=neutral,
PublicKeyToken=null."
MessageArg: null
ResourceId: -2146233054
TypeName: "System.Web.UI.WebControls.DataGrid"
so could you pls help me out with your expert advices on solving the problem
and generating the control dynamically.
your expert advice would be highly appreciated.
Rgds
Shiju
I have a dropdownlist with some values as .net server controls & a button ,
on clicking a button i need to generate the choosen contorl dynamically.
I am giving a small glimpse of my code for your understanding
the aspx page has dropdwon list with values as below.
<aspropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="Label">Label</asp:ListItem>
<asp:ListItem Value="DropDownList">DropDownList</asp:ListItem>
<asp:ListItem Value="DataGrid">DataGrid</asp:ListItem>
<asp:ListItem Value="DataList">DataList</asp:ListItem>
<asp:ListItem Value="CheckBox">CheckBox</asp:ListItem>
<asp:ListItem Value="RadioButton">RadioButton</asp:ListItem>
<asp:ListItem Value="RadioButton">RadioButton</asp:ListItem>
<asp:ListItem Value="Table">Table</asp:ListItem>
<asp:ListItem Value="TextBox">TextBox</asp:ListItem>
<asp:ListItem></asp:ListItem>
</aspropDownList>
now the code that gets executed at the click of the button is as follows
i am using the reflection name space
String strCtrlName = DropDownList1.SelectedItem.Value ;
Response.Write(strCtrlName);
Type tp=System.Type.GetType("System.Web.UI.WebControls."+strCtrlName ,true) ;
Object obj = Activator.CreateInstance(tp0;
PlaceHolder.Controls.Add(new obj );
but i get error at the line " Type
tp=System.Type.GetType("System.Web.UI.WebControls."+strCtrlName ,true) ; "
error below :
System.SystemException: {"Could not load type
System.Web.UI.WebControls.DataGrid from assembly TestingDynamicCtrl,
Version=1.0.1950.28617, Culture=neutral, PublicKeyToken=null."}
AssemblyName: "TestingDynamicCtrl, Version=1.0.1950.28617, Culture=neutral,
PublicKeyToken=null"
ClassName: "System.Web.UI.WebControls.DataGrid"
Message: "Could not load type System.Web.UI.WebControls.DataGrid from
assembly TestingDynamicCtrl, Version=1.0.1950.28617, Culture=neutral,
PublicKeyToken=null."
MessageArg: null
ResourceId: -2146233054
TypeName: "System.Web.UI.WebControls.DataGrid"
so could you pls help me out with your expert advices on solving the problem
and generating the control dynamically.
your expert advice would be highly appreciated.
Rgds
Shiju