Translate

Thursday, 5 February 2015

split string assign in gridview

 protected void btnShow_Click(object sender, EventArgs e)
    {
        string value = "Pabitra,Pabitra2,Pabitra3,Pabitra4,Pabitra5";
       // using System.Text.RegularExpressions;
       // string[] lines = Regex.Split(value, ",");
        string[] lines = value.Split(',');
        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        foreach (string line in lines)
        {
            DataRow dr = dt.NewRow();
            dr["Name"] = line;
            dt.Rows.Add(dr);
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

No comments:

Post a Comment