中继器单击“问题” [英] Repeater Click Issue

查看:87
本文介绍了中继器单击“问题”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试以下代码时出错。

错误消息:值不能为空。参数名称:source



这些是我收到错误的行。



FoodTypeResponseDto selectedFoodTypes = this .FoodTypes.FirstOrDefault(r => r.FoodTypeId == foodTypeID);



如何整理出来?



提前致谢。



I have got an error when try the following code.
Error Message: Value cannot be null. Parameter name: source

These are the lines where I got the error.

FoodTypeResponseDto selectedFoodTypes = this.FoodTypes.FirstOrDefault(r => r.FoodTypeId == foodTypeID);

How to sort it out?

Thanks in advance.

protected void RecipeManagementUserControl_RepeaterItemClick(object sender, CommandEventArgs e)
{

        if (e.CommandName == WellKnownCommandNames.Edit.ToString())
        {
           
            int foodTypeID = 0;
            if (!string.IsNullOrEmpty(e.CommandArgument.ToString()))
            {
                int.TryParse(e.CommandArgument.ToString(), out foodTypeID);

                this.FoodTypeID = foodTypeID;
                this.FoodType = ((LinkButton)(((RepeaterCommandEventArgs)(e)).CommandSource)).Text;

                LinkButton linkButton = (LinkButton)FindControl("foodTypeActionLinkButton");

                FoodTypeResponseDto selectedFoodTypes = this.FoodTypes.FirstOrDefault(r => r.FoodTypeId == foodTypeID);

                this.FoodType = selectedFoodTypes.Name;
                this.FoodTypeIndexID = selectedFoodTypes.IndexID;

                this.GetMultipleFoodData();
            }
        }
}

推荐答案

首先或默认就是这样,它返回第一个如果找不到该类型的项目或默认值。我猜它找不到它,引用类型的默认值为null。在你的this.foodType = selectedFoodTypes.Name中,selectedFoodTypes为null并在那里给你错误,就在那一行之前你需要检查它之前是否为null。
First or default is just that, it returns the first item or default for the type if it cannot find it. I''m guessing it can''t find it, and the default value for reference types is null. On your "this.foodType = selectedFoodTypes.Name", the selectedFoodTypes is null and giving you the error there, just before that line you need to check if its null before that.


这篇关于中继器单击“问题”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆