Reputation: 4297
You can create a DataList easily in asp.net, I need to add a default item at last position of Datalist, for example an item named "Add new Item", if Datalist is empty I can only see this default item if not I see it in last position. Hope I'm clear enough. Is this possible? if yes, HOW?
Upvotes: 0
Views: 494
Reputation: 228
Assuming that you're data binding your DataList, you just need to add "Add New Item" to your data source before calling DataBind on your DataList. I don't know what your data source is but the logic should be similar to whatever you're using. If you're binding to a DataTable you will need to make sure that the sort makes your "Add New Item" entry be the last one. You may need to add a sort column or something that you give your own incrementing id to and sort based on that column.
List<string> values = new List<string>();
values.Add("Item 1");
values.Add("Item 2");
values.Add("Add New Item");
DataList dataList = new DataList();
dataList.DataSource = values;
dataList.DataBind();
Upvotes: 1