raphael232
Programmer
Hi i am trying to create a dynamic web form which displays controls based on information stored in the database.
I have a formview control on my page and a repeater within that:
This works fine so far but notice i have not displayed the control on the page. Here's the structure for the attributes table:
- ID
- SectionID
- AttributeName
- AttributeType
What i need to do is add the control to the page based on the AttributeType value ie if AttributeType = "String" i would need to add a text box or if it equals "Image" i would need to add the image control.
I'm not too sure where to go on this as this is the most complicated thing i have had to do in asp.net so far.
Appreciate if someone could help. Thanks
I have a formview control on my page and a repeater within that:
Code:
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
<table>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td class="TableHeader"><%# Eval("AttributeName") %>: CONTROL HERE</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<asp:Button ID="btnInsert" CommandName="Insert" runat="server" Text="Insert" />
</InsertItemTemplate>
</asp:FormView>
/code]
I figured i could bind the data from the database to my repeater with the Page_Load event handler:
[code]
Dim attributesAdapter As New KITTableAdapters.AttributesTableAdapter
Dim Repeater1 As Repeater = CType(FormView1.FindControl("Repeater1"), Repeater)
Repeater1.DataSource = attributesAdapter.GetAttributesBySectionID(sectionID)
Repeater1.DataBind()
This works fine so far but notice i have not displayed the control on the page. Here's the structure for the attributes table:
- ID
- SectionID
- AttributeName
- AttributeType
What i need to do is add the control to the page based on the AttributeType value ie if AttributeType = "String" i would need to add a text box or if it equals "Image" i would need to add the image control.
I'm not too sure where to go on this as this is the most complicated thing i have had to do in asp.net so far.
Appreciate if someone could help. Thanks