Expand|Select|Wrap|Line Numbers
- 01.<asp:FormView runat="server" ID="fv1" PagerSettings-Visible="False"
- 02. EmptyDataText="No Image Set Found." EnableViewState="False"
- 03. AllowPaging="True">
- 04. <ItemTemplate>
- 05. <asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="Edit" />
- 06. </ItemTemplate>
- 07. <EditItemTemplate>
- 08. <br />
- 09. <asp:Label ID="lbl0" runat="server" Visible="False" Text="Or choose one from the list:">
- 10. </asp:Label>
- 11. <asp:TextBox ID="txt0" runat="server"
- 12. Text='<%# Bind("Field0") %>'></asp:TextBox>
- 13. <asp:RequiredFieldValidator ID="rfv0" runat="server" ErrorMessage="* Required" ControlToValidate="txt0" SetFocusOnError="True" CssClass="error"></asp:RequiredFieldValidator>
- 14.
- 15. </EditItemTemplate>
- 16. <PagerSettings Visible="False" />
- 17. </asp:FormView>
Expand|Select|Wrap|Line Numbers
- 1.<asp:DropDownList ID="ddl0" runat="server" Visible="false"
- 2. AutoPostBack="true" SkinID="DropDownList" AppendDataBoundItems="true" >
- 3.</asp:DropDownList>
Code-Behind in VB:
Expand|Select|Wrap|Line Numbers
- 01.ddl0.DataSource = imgTable
- 02.ddl0.DataTextField = "Name"
- 03.ddl0.DataValueField = "tableIndex"
- 04.ddl0.DataBind()
- 05.ddl0.Visible = True
- 06.
- 07.fv1.DataSource = ddl0.DataSource
- 08.fv1.DataBind()
I pulled the data from a SQL database using a SELECT command. Stored it in a Dataset. Pulled out the table and assigned it to variable of type DataTable called imgTable. imgTable gets assigned to the datasource of the DropDownList. The DropDownList's datasource gets assigned to the formview's datasource. I have it this way because they pull the same data, and 2, whatever selection changes in the dropdown should be reflected in the controls of the formview.
Now my PageLoad looks like:
Expand|Select|Wrap|Line Numbers
- 01.Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
- 02.
- 03. If Not Page.IsPostBack Then
- 04. lblMsg.Visible = False
- 05.
- fetchdata() 'Function to get the data from the SQL database.
- 06. BindData() 'Function to bind data to all page controls.
- 07. Else
- 08. If Not lblMsg.Text = "" Then
- 09. lblMsg.Visible = True
- 10. End If
- 11. fv1.DefaultMode = FormViewMode.Edit
- 12. End If
- 13. fv1.DataSource = imgTable
- 14. fv1.DataBind()
- 15.
- End Sub
Thanks,
Andy