Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update control within formview insertitemtemplate

Status
Not open for further replies.

raphael232

Programmer
Jun 9, 2006
51
0
0
GB
Hi, i have the following formview:

Code:
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" DefaultMode="Insert">
    <InsertItemTemplate>
        Title: <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
        Category: <asp:DropDownList ID="lstCategoryID" runat="server">
        </asp:DropDownList>
    </InsertItemTemplate>
</asp:FormView>

I need to be able to update the dropdownlist control to add in the categories for my page. Before (when i did not use a formview) i would have put:

Code:
Dim items As New ListItemCollection
Dim topItem As New ListItem

topItem.Text = "-- Please Select --"
topItem.Value = ""
items.Add(topItem)

lstCategoryID.DataSource = Utilities.GetCategoriesList(items, 0, "")
lstCategoryID.DataTextField = "Text"
lstCategoryID.DataValueField = "Value"
lstCategoryID.DataBind()

in my page load event handler but now i have moved it within my formview it doesn't seem to work. Appreciate if someone could tell me how to fix this. Thanks
 
You'll have to use FindControl to get a reference to the DropDownList then you can do the same as you have done above.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Couldn't you just do this?

Code:
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" DefaultMode="Insert">
    <InsertItemTemplate>
        Title: <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
        Category: <asp:DropDownList ID="lstCategoryID" runat="server" DataTextField="Text" DataValueField="Value" DataSource='<%# Utilities.GetCategoriesList(items, 0, "")   %>'>
        </asp:DropDownList>
    </InsertItemTemplate>
</asp:FormView>
 
Hi cheers i can get both methods working but i need to pass a variable called categoryID in the getCategoriesList above, ie:

<%# Utilities.GetCategoriesList(Nothing, categoryID, "") %>

but when i run this i get sectionID is not declared. How do i pass this variable to the function from my page load event handler?

Appreciate your help once more. Thanks
 
Perhaps you should set up a property that stores that value and in your GetCategoriesList method you retrieve the value there after setting it in the Page_Load?
 
This should be done in the code behind page. Try
Code:
lstCategoryID.DataSource = Utilities.GetCategoriesList(Nothing, categoryID, "")

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top