views:

52

answers:

3

Hello All,

I have a SharePoint List as Data Source and the data in it is not cleansed.

I want to display a column into a Drop down list. The data is like this:

  1. StackOverFlow
  2. StackOverFlow:XYZ
  3. StackOverFlow;123
  4. StackOverFlow,ABC

I want the "StackOverFlow" to be displayed in the dropdown. How can I ignore the text after any symbol and get it into a data table?

Please help.

+2  A: 

You might have to forcibly remove the separator characters yourself. It looks like these separators vary between ":," ";," and ",."

Is it possible to patch your Data Source prior to assigning it to the SharePoint list? In the patch code, you can write something like the following:

Regex exp = new Regex("^(.+?)\b.*$", RegexOptions.Compiled);

DataRow[col] = exp.Replace(Convert.ToString(DataRow[col]), "$1");

This regex replacement effectively removes all text on or after the first word boundary (periods, commas, etc.)

This is not a perfect solution, I realize, but it does work.

David Andres
A: 

From your example, do you want "StackOverFlow" to show 4 times in your list?

Jim
A: 

This is How I did that:

ArrayList  values = new ArrayList(); 
foreach (DataRow dr in Dt.Rows)
{
   string delimStr = ",.:;";
   char[] delimiter = delimStr.ToCharArray();
   string origString = dr["Title"].ToString();
   string[] cleansedString = origString .Split(delimiter);
   string Str= cleansedString [0];
   if (!values.Contains(Str))
   {
      values.Add(Str);
   }
}
values.Sort();
ddList.DataSource = values;
ddList.DataBind();

Thank you for the support!!

Pradeep007