Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取asp.net repeater中HiddenField的值_C#_Asp.net_Repeater - Fatal编程技术网

C# 获取asp.net repeater中HiddenField的值

C# 获取asp.net repeater中HiddenField的值,c#,asp.net,repeater,C#,Asp.net,Repeater,当我尝试在中继器内部使用隐藏字段时 <repeater> <repeater> <hiddenfield> 为什么会出现错误?看起来hf为空,因为您试图使用temp.FindControl而不是temp.Items[count].FindControl来查找HiddenField 更改以下内容 DropDownList ds = (DropDownList)temp.FindControl("userdropdown"); HiddenFie

当我尝试在中继器内部使用隐藏字段时

<repeater>
   <repeater>
     <hiddenfield>

为什么会出现错误?

看起来
hf
为空,因为您试图使用
temp.FindControl
而不是
temp.Items[count].FindControl来查找
HiddenField

更改以下内容

DropDownList ds = (DropDownList)temp.FindControl("userdropdown");
HiddenField hf = (HiddenField)temp.FindControl("hiddenid");
对此

DropDownList ds = (DropDownList)temp.Items[count].FindControl("userdropdown");
HiddenField hf = (HiddenField)temp.Items[count].FindControl("hiddenid");
更新

如果
ds.SelectedValue
为空字符串或包含非数字字符,此行将引发错误

user.user_id  = int.Parse(ds.SelectedValue);
你需要把它改成这个

int userID = 0;
if (int.TryParse(ds.SelectedValue, out userID))
{
    user.user_id  = userID;
}
else
{
    // do something when ds.SelectedValue is non numeric
}
试试这个

foreach (RepeaterItem items in temp.Items)
        {
            DropDownList ds = (DropDownList)items.FindControl("userdropdown");
            HiddenField hf = (HiddenField)items.FindControl("hiddenid");

          //your code
        }

亲爱的,你们们有嵌套的Repeter,若你们们的意思是向repeater添加一个数据源,当然我有,但并没有提及,因为这是一个很长的查询,但它是有效的。。。但现在我得到了这个错误:System.FormatException:输入字符串的格式不正确。行内:user.user\u id=int.Parse(ds.SelectedValue);但是用户id是int,以确定
ds的值是多少。SelectedValue
?如果是空字符串,则
int.Parse
将抛出错误。
user.user_id  = int.Parse(ds.SelectedValue);
int userID = 0;
if (int.TryParse(ds.SelectedValue, out userID))
{
    user.user_id  = userID;
}
else
{
    // do something when ds.SelectedValue is non numeric
}
foreach (RepeaterItem items in temp.Items)
        {
            DropDownList ds = (DropDownList)items.FindControl("userdropdown");
            HiddenField hf = (HiddenField)items.FindControl("hiddenid");

          //your code
        }