1

在我的数据集中,我有很多行,

In first row last column has the value is "12356.56@Firefox 1@23423"
In Second row same column has the value is "12356.56@Chrome2.0@23423"
In Third row same column has the value is "3423@Firefox 14.0@sdfsd"

在这里而不是像上面那样显示相同的值..

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

我该怎么做...

4

3 回答 3

1

使用这个辅助函数

public static string GetBrowser(string str)
{
    str = str.ToUpper();
    if(str.Contains("CHROME"))
    {
        return "Chrome";
    } 
    else if(str.Contains("FIREFOX")) 
    {
        return "Firefox";
    }
    return "Unknown";
}

然后,当您将数据集绑定到 UI 时,使用它来显示值。

于 2012-08-30T13:06:41.217 回答
1

如果您有要检查的内容列表,可以使用.Contains以下方法检查:

var myValue = myDS[rowIndex][lastColumn].ToString();
if (myValue.Contains("Firefox"))
    return "Firefox";
else if (myValue.Contains("Chrome"))
    return "Chrome";
else
    return "Unknown";

演示:http: //ideone.com/pMVeD


从您给出的示例中,似乎以下逻辑可能有效,但应该针对更广泛的样本值进行测试:

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];

演示:http: //ideone.com/NrY1e

于 2012-08-30T13:06:47.830 回答
1

这是代码。这可能会有所帮助。

        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();
于 2012-08-30T13:18:46.820 回答