dEaDfRoG Posted October 3, 2003 Posted October 3, 2003 Hi chaps - and apologies if this is a stupid question, but I just cannot get it to work!! I'm trying to create an ASP.NET admin page, using a DataList with EditItemTemplate. I've gotten it to work nicely for a single textbox, but I also need to add a drop down list, and pre-populate it with items from my database. Think of it as if I were creating a list of towns - and each town must come from a region. When a user creates/edits a town, they must also select a region that the town is part of from a drop down list. I can get the DDL to appear, but how on earth do I populate it with data as part of an EditItemTemplate within a DataList? I hope someone knows what I'm rambling on about, and I would truly appreciate any help or advice anyone can give. Thanks for reading! Andy. Quote
dEaDfRoG Posted October 4, 2003 Author Posted October 4, 2003 I think what I'm struggling with is where I put the code to populate the DDL. The problem seems to be that the ddlRegionID as I call it isn't actually rendered until the edit button is clicked in the datalist. My apologies if I sound thick, it's probably something really obvious, but it's really annoying (especially considering how easy this would be in classic ASP!) Here's what I have: <asp:DataList id="dlstLocations" OnEditCommand="dlstLocations_EditCommand" OnCancelCommand="dlstLocations_CancelCommand" OnDeleteCommand="dlstLocations_DeleteCommand" OnUpdateCommand="dlstLocations_UpdateCommand" DataKeyField="LocationID" runat="server"> <itemtemplate> <%# Container.DataItem("Location")%><br /> <asp:LinkButton Text="Edit" CommandName="edit" runat="server" /> </itemtemplate> <edititemtemplate> <asp:TextBox id="txtLocation" text='<%# Container.DataItem("Location") %>' runat="server" /> <asp:DropDownList id="ddlRegionID" runat="server" /><br /> <asp:LinkButton text="Update" CommandName="update" runat="server" /> <asp:LinkButton text="Delete" CommandName="delete" runat="server" /> <asp:LinkButton text="Cancel" CommandName="cancel" runat="server" /> </edititemtemplate> </asp:DataList> Quote
aewarnick Posted October 4, 2003 Posted October 4, 2003 You may want to post this question in the asp section. I know nothing about it yet. Quote C#
dEaDfRoG Posted October 4, 2003 Author Posted October 4, 2003 Hi chaps - and apologies if this is a stupid question, but I just cannot get it to work!! I posted this in the general section and was advised to post here instead. I'm trying to create an ASP.NET admin page, using a DataList with EditItemTemplate. I've gotten it to work nicely for a single textbox, but I also need to add a drop down list, and pre-populate it with items from my database. Think of it as if I were creating a list of towns - and each town must come from a region. When a user creates/edits a town, they must also select a region that the town is part of from a drop down list. I can get the DDL to appear, but how on earth do I populate it with data as part of an EditItemTemplate within a DataList? I hope someone knows what I'm rambling on about, and I would truly appreciate any help or advice anyone can give. I think what I'm struggling with is where I put the code to populate the DDL. The problem seems to be that the ddlRegionID as I call it isn't actually rendered until the edit button is clicked in the datalist. My apologies if I sound thick, it's probably something really obvious, but it's really annoying (especially considering how easy this would be in classic ASP!) Here's what I have: <aspataList id="dlstLocations" OnEditCommand="dlstLocations_EditCommand" OnCancelCommand="dlstLocations_CancelCommand" OnDeleteCommand="dlstLocations_DeleteCommand" OnUpdateCommand="dlstLocations_UpdateCommand" DataKeyField="LocationID" runat="server"> <itemtemplate> <%# Container.DataItem("Location")%><br /> <asp:LinkButton Text="Edit" CommandName="edit" runat="server" /> </itemtemplate> <edititemtemplate> <asp:TextBox id="txtLocation" text='<%# Container.DataItem("Location") %>' runat="server" /> <aspropDownList id="ddlRegionID" runat="server" /><br /> <asp:LinkButton text="Update" CommandName="update" runat="server" /> <asp:LinkButton text="Delete" CommandName="delete" runat="server" /> <asp:LinkButton text="Cancel" CommandName="cancel" runat="server" /> </edititemtemplate> </aspataList> Thanks for reading! Andy. Quote
mr relaxo Posted October 4, 2003 Posted October 4, 2003 you can call a function to populate your drop down list with different data to what your binding your datalist to. <asp:listbox id=blah runat=server datasource="<%# fiillmybox() %>" /> and then your function would return a datatable or whatever is appropriate to bind to your control. i may have misunderstood your problem tho, its very a.m :p Quote You can not get ye flask.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.