Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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
Javascript 如果有多个签入复选框C,如何发出警报#_Javascript_C#_Gridview_Checkbox_Alert - Fatal编程技术网

Javascript 如果有多个签入复选框C,如何发出警报#

Javascript 如果有多个签入复选框C,如何发出警报#,javascript,c#,gridview,checkbox,alert,Javascript,C#,Gridview,Checkbox,Alert,我正在制作一块板,现在我想在选中复选框时编辑该项目 但是,正如您所知,复选框可以选中任何复选框 在我的规则中,我只想编辑一项 所以我想在选中多个复选框时显示警告消息 我该怎么做??我不想禁用它 因为删除项目时,我使用了多选复选框 我的代码如下 protected void lnkbtnEdit_Click(object sender, EventArgs e) { string editPageUrl = string.Empty; foreach (GridViewRow gR

我正在制作一块板,现在我想在选中复选框时编辑该项目

但是,正如您所知,复选框可以选中任何复选框

在我的规则中,我只想编辑一项

所以我想在选中多个复选框时显示警告消息

我该怎么做??我不想禁用它

因为删除项目时,我使用了多选复选框

我的代码如下

protected void lnkbtnEdit_Click(object sender, EventArgs e)
{
    string editPageUrl = string.Empty;
    foreach (GridViewRow gRow in grvList.Rows)
    {
       CheckBox chkbox = (CheckBox)gRow.FindControl("chk");

       if (chkbox.Checked)
       {
          int id = Convert.ToInt32(gRow.Cells[1].Text);
                    editPageUrl = "http://ycchoi/sites/dev/_layouts/15/ListItemControl/EditListItem.aspx?ID=" + id;
          Response.Redirect(editPageUrl);
        }
        else
        {
           string message = @"
              <script type='text/javascript'>
                        alert('Please select item to Edit');
              </script>";
            ClientScript.RegisterClientScriptBlock(GetType(), "script", message);
                }
            }
        }
protectedvoid lnkbtnEdit\u单击(对象发送方,事件参数e)
{
string editPageUrl=string.Empty;
foreach(GridViewRow在grvList.Rows中增长)
{
复选框chkbox=(复选框)gRow.FindControl(“chk”);
如果(chkbox.Checked)
{
int id=Convert.ToInt32(gRow.Cells[1].Text);
editPageUrl=”http://ycchoi/sites/dev/_layouts/15/ListItemControl/EditListItem.aspx?ID=“+id;
重定向(editPageUrl);
}
其他的
{
字符串消息=@“
警报(“请选择要编辑的项目”);
";
RegisterClientScriptBlock(GetType(),“script”,消息);
}
}
}

我会在foreach循环之外保留一个变量,存储选中行的ID,然后查看该列表的长度,看看它是否等于1,然后再允许用户编辑它。这就是我在类似界面中的做法(用户可以删除/隐藏/突出显示多个内容,但一次只能回复一个。)

List id=new List();
foreach(GridViewRow在grvList.Rows中增长)
{
复选框chkbox=(复选框)gRow.FindControl(“chk”);
如果(chkbox.Checked)
{
int id=Convert.ToInt32(gRow.Cells[1].Text);
editPageUrl=”http://ycchoi/sites/dev/_layouts/15/ListItemControl/EditListItem.aspx?ID=“+id;
添加(id);
}
}
如果(ids.Count==1)
{
//使用ID[0]执行某些操作
}
其他的
{
//显示错误
}

如果您只想允许一个选择,请使用
单选按钮
。这就是他们设计的目的。有没有其他办法解决这个问题?我选择复选框原因当我删除项目时(对于多选)正是我想要的!!谢谢你libertyernie
List<int> ids = new List<int>();
foreach (GridViewRow gRow in grvList.Rows)
{
   CheckBox chkbox = (CheckBox)gRow.FindControl("chk");

   if (chkbox.Checked)
   {
      int id = Convert.ToInt32(gRow.Cells[1].Text);
                editPageUrl = "http://ycchoi/sites/dev/_layouts/15/ListItemControl/EditListItem.aspx?ID=" + id;
      ids.Add(id);
    }
}

if (ids.Count == 1)
{
    // do something with ids[0]
}
else
{
    // show error
}