Reputation: 1201
In my dataset I have many rows,
In first row last column has the value is "12356.56@Firefox 1@23423"
In Second row same column has the value is "[email protected]@23423"
In Third row same column has the value is "3423@Firefox 14.0@sdfsd"
here instead of displaying same value like above..
I need to display just "Firefox" if that column has Firefox in UI
I need to display just "Chrome" if that column has Chromein UI
how can i do it...
Upvotes: 1
Views: 5033
Reputation: 928
Here is code. This might help.
DataSet ds = new DataSet();
//DataTable dt = new DataTable();
ds.Tables.Add("table0");
DataColumn dc = new DataColumn("browser");
ds.Tables[0].Columns.Add(dc);
ds.Tables[0].Rows.Add("12356.56@Firefox1@23423");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string str = ds.Tables[0].Rows[i][0].ToString();
if((str.ToLower().CompareTo("firefox"))!=0)
{
ds.Tables[0].Rows[i][0] = "firefox";
}
}
_gridView.DataSource = ds;
_gridView.DataBind();
Upvotes: 1
Reputation: 56769
If you have a list of things you want to check for, you can use .Contains
to check:
var myValue = myDS[rowIndex][lastColumn].ToString();
if (myValue.Contains("Firefox"))
return "Firefox";
else if (myValue.Contains("Chrome"))
return "Chrome";
else
return "Unknown";
Demo: http://ideone.com/pMVeD
From the examples you've given, it appears the following logic may work, but it should be tested against a wider variety of sample values:
var myValue = myDS[rowIndex][lastColumn].ToString();
var parts = myValue.Split('@');
var browser = parts[1].Split(' ','0','1','2','3','4','5','6','7','8','9');
return browser[0];
Demo: http://ideone.com/NrY1e
Upvotes: 1
Reputation: 31077
Use this helper function
public static string GetBrowser(string str)
{
str = str.ToUpper();
if(str.Contains("CHROME"))
{
return "Chrome";
}
else if(str.Contains("FIREFOX"))
{
return "Firefox";
}
return "Unknown";
}
Then when you bind the dataset to the UI use it to display the value.
Upvotes: 1