Create a Comma Separated String from A List of String in ASP.NET

Create a Comma Separated String from A List of String in asp.net
.cs File Code:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7.   
  8. public partial class UserControls_CommaSeparatedControl: System.Web.UI.UserControl {  
  9.     // Declaring List as static  
  10.   
  11.     static List < string > strList = new List < string > ();  
  12.   
  13.     protected void Page_Load(object sender, EventArgs e)   
  14.     {  
  15.         if (!IsPostBack) {  
  16.             // Clearing the List ob its first load  
  17.             strList.Clear();  
  18.         }  
  19.     }  
  20.   
  21.     protected void BtnSave_Click(object sender, EventArgs e)   
  22.     {  
  23.         CreateListOfString();  
  24.     }  
  25.   
  26.     private void CreateListOfString()   
  27.     {#region--Create list of string--  
  28.   
  29.         try  
  30.         {  
  31.   
  32.             if (txtSomeText.Text != "")  
  33.             {  
  34.                 strList.Add(txtSomeText.Text);  
  35.   
  36.                 txtSomeText.Text = "";  
  37.             }  
  38.   
  39.             GridView1.DataSource = strList;  
  40.             GridView1.DataBind();  
  41.   
  42.             string Result = GetSeparateTheString(strList, ", ");  
  43.   
  44.             LblResult.Text = Result;  
  45.         }   
  46.      catch (Exception Exc)   
  47.         {  
  48.             LblMessage.Text = "Application Error : " + Exc.Message;  
  49.         }  
  50.  
  51.         #endregion  
  52.   
  53.     }  
  54.   
  55.     private string GetSeparateTheString(List < string > strList, string comma)   
  56.     {#region--Create a Comaa Separated string--  
  57.   
  58.         try   
  59.         {  
  60.   
  61.             System.Text.StringBuilder sb = new System.Text.StringBuilder();  
  62.   
  63.             foreach(string str in strList)   
  64.             {  
  65.                 // If this statement found any value in the String Builder Object, it will add comma one after another.  
  66.   
  67.                 if (sb.Length > 0)   
  68.                 {  
  69.                     sb.Append(comma);  
  70.                 }  
  71.   
  72.                 // in its first pass it will take the first string , then others string: because this line must execute  
  73.   
  74.                 sb.Append(str);  
  75.             }  
  76.   
  77.             return sb.ToString();  
  78.         } catch (Exception Exc)   
  79.         {  
  80.             LblMessage.Text = "Application Error : " + Exc.Message;  
  81.   
  82.             return "";  
  83.         }  
  84.  
  85.         #endregion  
  86.     }