如何修复“x 是一个变量,但像方法一样使用"C#中的语法错误?

编程入门 行业动态 更新时间:2024-10-24 12:30:35
本文介绍了如何修复“x 是一个变量,但像方法一样使用"C#中的语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I am getting the following error working on gradrid footer totals "'fitem' is a 'variable' but is used like a 'method'"

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";
        }
    }
}

推荐答案

你的台词

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

应该是

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

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

since the [] brackets are for accesing an index and the () brackets are used to call methods.

这篇关于如何修复“x 是一个变量,但像方法一样使用"C#中的语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 13:15:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是一个   变量   语法错误   方法   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!