简体   繁体   English

错误:缺少using指令或程序集引用?

[英]Error: missing a using directive or an assembly reference?

protected void gvdet_DataBound(object sender, GridViewRowEventArgs e)
{
    string employeeName = dsOLDData.SelectedItem.Text; -- ERROR HERE :(

    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        foreach (TableCell c in e.Row.Cells)
        {
            if (c.Controls[0] is DataBoundLiteralControl)
            {
                DataBoundLiteralControl ctl = (DataBoundLiteralControl)c.Controls[0];
                if (ctl.Text.Contains(employeeName))
                {
                    c.BackColor = System.Drawing.Color.Yellow;
                    c.ForeColor = System.Drawing.Color.Blue;
                }
            }

        }
    }
  }
}

ERROR: Error 2 'System.Web.UI.WebControls.LinqDataSource' does not contain a definition for 'SelectedItem' and no extension method 'SelectedItem' accepting a first argument of type 'System.Web.UI.WebControls.LinqDataSource' could be found (are you missing a using directive or an assembly reference?) 错误:错误2'System.Web.UI.WebControls.LinqDataSource'不包含'SelectedItem'的定义,也没有扩展方法'SelectedItem'接受类型为'System.Web.UI.WebControls.LinqDataSource'的第一个参数找到(您是否缺少using指令或程序集引用?)

Are you really sure, "dsOLDData" is a Dropdownlist. 您真的确定“ dsOLDData”是一个下拉列表。 The errormessage seems to say it's an instance of System.Web.UI.WebControls.LinqDataSource 错误消息似乎表明它是System.Web.UI.WebControls.LinqDataSource的一个实例

The "ds" at the beginning of "dsOLDData" would be a sign for me, too, that it's a D ata S ource 在“DS”在“dsOLDData”的开始将是我一个手势,那就是,这是一个d ATA 小号乌尔斯河

Try calling DataBind on your DropDownList before accessing it's selected item. 在访问其选定项之前,尝试在DropDownList上调用DataBind。 It may not have bound to any data at the point your GridView does. 在GridView上,它可能尚未绑定任何数据。 eg. 例如。

dsOLDData.DataBind();
string employeeName = dsOLDData.SelectedItem.Text;

Not sure if that will help, but worth a go... 不确定是否会有所帮助,但值得一试...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM