Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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# 尝试在GridView编辑中填充下拉列表_C#_Asp.net_Gridview - Fatal编程技术网

C# 尝试在GridView编辑中填充下拉列表

C# 尝试在GridView编辑中填充下拉列表,c#,asp.net,gridview,C#,Asp.net,Gridview,当我在网格视图上单击“编辑”时,有以下代码试图填充下拉列表,它给出了以下错误: " 'ddlgvRoom' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value" 你知道我为什么需要在行编辑事件中添加代码吗?如果是,你能帮我吗?我的gridview正在从objectdatasource获取其值 protected void Gr

当我在网格视图上单击“编辑”时,有以下代码试图填充下拉列表,它给出了以下错误:

" 'ddlgvRoom' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
你知道我为什么需要在行编辑事件中添加代码吗?如果是,你能帮我吗?我的gridview正在从objectdatasource获取其值

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow &&
            (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
        {
            DropDownList dl = (DropDownList)e.Row.FindControl("ddlgvRoom");
        }
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        DropDownList ddlgvRoom = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlgvRoom");
        string strgvRoom = ddlgvRoom.SelectedItem.Text.ToString();

        DropDownList ddlgvJack = (DropDownList)
            GridView1.Rows[e.RowIndex].FindControl("ddlgvJack");
        string strgvJack = ddlgvJack.SelectedItem.Text.ToString();

        DropDownList ddlgvVlan = (DropDownList)
            GridView1.Rows[e.RowIndex].FindControl("ddlgvVlan");
        string strgvVlan = ddlgvVlan.SelectedItem.Text.ToString();
        GridView1.DataBind();

    }
}

必须去掉HTML端的selectedvalue,然后所有内容都开始工作

在哪一行出现该错误?在代码周围放置一个try-catch,并捕获异常,然后向我们解释更多细节。您现在在GridView1_RowDataBound中所做的没有任何意义,因为一旦获得dl对象,您就不会对其执行任何操作。感谢您的响应,我尝试填充我的ddlgvRoom,没有错误,只是说所选值不存在,但当我调试它时,值显示得很好。我单击gridview编辑按钮后,它似乎失去了该值