For splitting values that is inserted with commas in table as for example mango,banana,apple etc
dataset ds100 = quicksearch.select_product_type(); if (ds100.Tables[0].Rows.Count != 0) { for (int k = 0; k <= ds100.Tables[0].Rows.Count - 1; k++) { example = Convert.ToString(ds100.Tables[0].Rows[k]["product_type"].ToString()); //product type field name////////////// int z = Convert.ToInt32(ds100.Tables[0].Rows[k]["company_id"].ToString()); string[] me = example.Split(','); int i; for (i = 0; i <= me.Length - 1; i++) { Label3.Visible = false; try { if (me[i] == DropDownList7.SelectedItem.Text) { try { quicksearch.get_company_id = z; ds = quicksearch.companysearch(); if (ds.Tables[0].Rows.Count != 0) { //creating grid view in runtime Label3.Visible = false; GridView dg = new GridView(); dg.AllowPaging = true; dg.PageSize = 50; dg.Width = 50; dg.Height = 50; dg.DataSource = ds; dg.DataBind();
Panel5.Visible = true; Panel5.Controls.Add(dg); flag = 1; } else { // Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('No Data Found')</script>"); Panel5.Visible = false; } } catch (Exception ex) { } } else { } }
catch (Exception ex) { // Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('No Data Found')</script>"); } } if (flag==0) { //Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('No Data Found')</script>"); Panel5.Visible = false; } PagedDataSource page = new PagedDataSource(); page.AllowPaging = true; } } else { // Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('No Data Found')</script>"); } if (flag == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('No Data Found')</script>");
Panel5.Visible = false; }
|
| Author: Deepak S 14 Aug 2008 | Member Level: Gold Points : 2 |
Hai, U can also use dis for splitting
For examples we have ID's separated by commas & want the names. We can use as:
string _AllIDS = string.Empty; _AllIDS = _dtSent.Rows[0]["SendTo"].ToString(); string[] _NameArray = _AllIDS.Split(','); for (int i = 0; i < _NameArray.Length; i++) { int _ID = Convert.ToInt32(_NameArray[i].ToString()); GetFullName(_ID); string _AllNames = hfFullName.Value.ToString(); lblFrom.Text = _AllNames.TrimEnd(',', ' '); }
|