Yves
Yves

Reputation: 12497

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?)

Upvotes: 0

Views: 5945

Answers (2)

Dan Diplo
Dan Diplo

Reputation: 25339

Try calling DataBind on your DropDownList before accessing it's selected item. It may not have bound to any data at the point your GridView does. eg.

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

Not sure if that will help, but worth a go...

Upvotes: 0

Xn0vv3r
Xn0vv3r

Reputation: 18184

Are you really sure, "dsOLDData" is a Dropdownlist. The errormessage seems to say it's an instance of System.Web.UI.WebControls.LinqDataSource

The "ds" at the beginning of "dsOLDData" would be a sign for me, too, that it's a Data Source

Upvotes: 1

Related Questions