0

I don't seem to be able to find a single hint at this on the Internet anywhere.

I've got an ASP.NET page with a RadioButtonList control, databound to a table in an SQL database. That works fine. I've also explicitly declared an extra "Unknown" list item, which handles any records in the database where the bound field is NULL.

However, I'd like the "Unknown" option to appear AFTER all of the other items pulled from the database. Since the property is called AppendDataBoundItems I suppose it's logical that they're going to come after any explicitly declared items, but isn't there a way to have the databound items appear first? I realise that I could achieve this by adding the "Unknown" option programmatically, but that seems like overkill!

Philip Stratford
  • 4,513
  • 4
  • 45
  • 71

2 Answers2

0

I realise that I could achieve this by adding the "Unknown" option programmatically, but that seems like overkill!

That's not overkill, just do that, and move on to the next part of the job.

Ben
  • 34,935
  • 6
  • 74
  • 113
  • I've got dozens of such lists on the page, I wanted to avoid the overhead of having all these extra items added when the page loads. – Philip Stratford Aug 13 '12 at 11:27
  • Then create an override, which overrides the databind to: 1. Count how many are already in the list. 2. Call the base class 3. Move the static ones to the end. – Ben Aug 13 '12 at 11:29
0

AppendDataBoundItems is for adding items before databinding.

See: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.appenddatabounditems.aspx

So, your only option is to do it by hand, then you have all the flexibility you need. You can insert (any position) or add items at the end of the range.

Tys
  • 3,592
  • 9
  • 49
  • 71