i need to display some text boxes, and 开发者_如何学编程have the ability for the user to "add another row"
i tried a datalist and a repeater, but it does not show anything at all, when the controls are blank.
<asp:DataList id="dlIso" runat="server" RepeatColumns="2" RepeatDirection="vertical" >
<ItemTemplate>
test</ItemTemplate>
</asp:DataList>
so in this case "test" does now show at all..
what is the best way to get this accomplished?
Thank you!
In order to provide "Add Another Row" functionality for either a Repeater or a DataList, you will have to add another item to whatever datasource you're binding the control to, and call .DataBind().
If you're databinding to something that initially contains no records, you should use a control with an EmptyDataTemplate (GridView, ListView, or DetailsView). For what you're doing, I would probably recommend the ListView.
You need to look at the InsertItemTemplate
.
Sorry, that is for the new ListView
. I think last time I did this I used the FooterTemplate
:
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/datalist.aspx
I don't know if this is the way it should be done, but the footer stays regardless of the current page, so the insert controls are always visible. It works well. You can also simulate the command hyperlinks (edit, update, cancel, etc), but I can't remember off-hand how.
A good set of articles for the ListView
can be found here:
https://web.archive.org/web/20211016204339/http://www.4guysfromrolla.com/articles/061709-1.aspx
The linked page is also the one that discusses inserts, but I'd advise reading the lot as it starts from the beginning.
Problem is that until you don't bind your repeater to some datasource
it will not show up any thing from the itemtemplate ... so you need to create some datasource
against the text boxes and for every new row add an item to that datasource
and re-bind the repeater ..
the number of item in your datasource
is the number of rows you will get displayed on the front
精彩评论