0

我在处理 gradrid 页脚总计时遇到以下错误“'fitem' 是一个'变量',但用作'方法'”

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridFooterItem)
    {
        GridFooterItem fitem = (e.Item as GridFooterItem);
        string value1 = fitem("CALENDAR_DAYS_MTD").Text;
        string value2 = fitem("WEEKENDS_MTD").Text;
        string value3 = fitem("HOLIDAYS_MTD").Text;
        string value4 = fitem("BUSINESS_DAYS_MTD").Text;
        int footervalue1 = Convert.ToInt32(value1.Split(':')[1]);
        int footervalue2 = Convert.ToInt32(value2.Split(':')[1]);
        int footervalue3 = Convert.ToInt32(value3.Split(':')[1]);
        int footervalue4 = Convert.ToInt32(value4.Split(':')[1]);
        //to get the value only.
        if (footervalue2 + footervalue3 + footervalue4 > footervalue1)
        {
            fitem("WEEKENDS_MTD").Style("color") = "Black";
            fitem("HOLIDAYS_MTD").Style("color") = "Black";
            fitem("BUSINESS_DAYS_MTD").Style("color") = "Black";


        }
        else
        {
            fitem("WEEKENDS_MTD").Style("color") = "Red";
            fitem("HOLIDAYS_MTD").Style("color") = "Red";
            fitem("BUSINESS_DAYS_MTD").Style("color") = "Red";
        }
    }
}
4

4 回答 4

5

你的台词

fitem("WEEKENDS_MTD").Style("color") = "Black";

应该是

fitem["WEEKENDS_MTD"].Style["color"] = "Black";

因为[]括号用于访问索引,而()括号用于调用方法。

于 2012-08-22T20:39:38.057 回答
0

你有这个:

 GridFooterItem fitem = (e.Item as GridFooterItem);
 string value1 = fitem("CALENDAR_DAYS_MTD").Text;

使用fitem("CALENDAR_DAYS_MTD")可能应该是fitem["CALENDAR_DAYS_MTD"].

于 2012-08-22T20:40:06.053 回答
0

我认为您正在考虑使用括号进行索引的 VB.NET,但这是 C#。它应该是:

fitem["CALENDAR_DAYS_MTD"].Text // Note the square brackets replacing the parens.

不是:

fitem("CALENDAR_DAYS_MTD").Text 
于 2012-08-22T20:40:16.140 回答
0

只要您使用 C#,就应该使用方括号而不是括号来引用索引。

fitem["WEEKENDS_MTD"].Style["color"] = "Black";

VB.NET 使用括号作为索引。

于 2012-08-22T20:40:18.580 回答