Hi,
Please refer below code.
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
List<string> countries = new List<string>();
DataTable dtCountries = new DataTable();
dtCountries.Columns.Add("CountryId");
dtCountries.Columns.Add("CountryName");
dtCountries.Rows.Add(1, "India");
dtCountries.Rows.Add(2, "Afganistan");
dtCountries.Rows.Add(3, "Pakistan");
dtCountries.Rows.Add(4, "Tajkistan");
dtCountries.Rows.Add(5, "Turkmanistan");
foreach (DataRow row in dtCountries.Rows)
{
countries.Add(string.Format("{0}-{1}", row["CountryId"], row["CountryName"]));
}
hfCountries.Value = string.Join(";", countries);
}
}
I hope this will help you out.