Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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
如何测试gridview的一行是否为空asp.net_Asp.net_Gridview_Webforms_Dropdown_Rowdatabound - Fatal编程技术网

如何测试gridview的一行是否为空asp.net

如何测试gridview的一行是否为空asp.net,asp.net,gridview,webforms,dropdown,rowdatabound,Asp.net,Gridview,Webforms,Dropdown,Rowdatabound,我在页面加载时有一个空的网格视图。 在RowDataBound事件中,我向最后一个单元格添加了dropdownlist 问题是ddl在页面加载时显示。 如果行的单元格为空,我想将其隐藏 protected void grw_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { D

我在页面加载时有一个空的网格视图。 在RowDataBound事件中,我向最后一个单元格添加了dropdownlist 问题是ddl在页面加载时显示。 如果行的单元格为空,我想将其隐藏

protected void grw_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddl = e.Row.FindControl("ddlAccepted") as DropDownList;
            if (null != ddl)
            {
                string acceptedKey = (e.Row.FindControl("lblAccepted") as Label).Text;
                string acceptedValue = "";
                if (acceptedKey == "True")
                {
                    acceptedValue = "Oui";
                }
                else if (acceptedKey == "False")
                {
                    acceptedValue = "Non";
                }

                ddl.Items.Add(new ListItem("Non", "False"));
                ddl.Items.Add(new ListItem("Oui", "True"));

                ddl.SelectedValue = acceptedValue;
            }


        }

    }
谢谢。

请尝试以下代码:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    // Check if the first two cells of row are not empty
    if (e.Row.Cells[0].Text != "" || e.Row.Cells[1].Text != "")
    {
        DropDownList ddl = e.Row.FindControl("ddlAccepted") as DropDownList;
        if (null != ddl)
        {
            string acceptedKey = (e.Row.FindControl("lblAccepted") as Label).Text;
            string acceptedValue = "";
            if (acceptedKey == "True")
            {
                acceptedValue = "Oui";
            }
            else if (acceptedKey == "False")
            {
                acceptedValue = "Non";
            }

            ddl.Items.Add(new ListItem("Non", "False"));
            ddl.Items.Add(new ListItem("Oui", "True"));

            ddl.SelectedValue = acceptedValue;
        }
    }
}
只需在代码中添加此
(如果
检查):

// Check if the first two cells of row are not empty
if (e.Row.Cells[0].Text != "" || e.Row.Cells[1].Text != "")
{
    //... do some other code here
}
我找到了解决办法 空单元格的文本等于
所以我加上这一行,它就行了

if (e.Row.Cells[0].Text != " ")

您是如何填充gridview的?
string requete=“选择”“作为id”“作为案例编号”“作为干预者”“作为请求者”“作为发送日期”“作为收件人”“作为接收日期”“作为状态代码”“作为IsAccepted”;grw.DataSource=GetEmptyDataSet(重新查询);grw.DataBind()
GetEmptyDataSet返回没有行或有空行的数据集?
public静态数据表GetEmptyDataSet(字符串查询){DataTable DataTable=null;SqlConnection=null;try{connection=Open();SqlCommand=new SqlCommand(查询,连接);SqlDataAdapter adapter=new SqlDataAdapter(命令);dataTable=new dataTable();adapter.Fill(dataTable);}最后{Close(连接);}返回dataTable;}