当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Split Eval in DropdownList

问题描述:

Hello I have an Eval value (one;two;three) which I want to split and display it in DropDownList.

DataSource='<%# Convert.ToString(Eval("DataNames")).Split(';')[] %>'

This line doesn't work and gives me error: The server tag is not well formed.

Also if I leave DataSource like this:

DataSource='<%# Eval("DataNames") %>'

I get every single character in a new line.

Can anyone help me with this?

网友答案:

Two issues here:

  1. [] is an incorrect syntax
  2. Single quotes are already used aroung the attribute value so you need to escape them inside the Split call.

Result should be something like that:

DataSource='<%# Convert.ToString(Eval("DataNames")).Split(\';\') %>'

Update. So apparently quotation is still wrong. You can try also using string instead of char in Split call (remember it has second parameter):

DataSource='<%# Convert.ToString(Eval("DataNames")).Split(";", StringSplitOptions.RemoveEmptyEntries) %>'

Or let go the outer quotes completely:

DataSource=<%# Convert.ToString(Eval("DataNames")).Split(';') %>
分享给朋友:
您可能感兴趣的文章:
随机阅读: