question

GonzalezLunaEstebanEliud-3790 avatar image
0 Votes"
GonzalezLunaEstebanEliud-3790 asked Viorel-1 answered

System.Web.HttpException: 'DataBinding: 'System.Data.DataRowView' does not contain a property with the name

Hello, I'm using DataBind for show a column of SQL DB in a DropDownList.
The program works but when I change the case of DropDownList, this issue appear.

 void ddlTurno()
         {
             ddlTablas.DataSource = null;
             ddlTablas.DataBind();
             SqlConnection con = new SqlConnection(connectionString);
             string com = "Select DISTINCT Turno from ee";
             SqlDataAdapter adpt = new SqlDataAdapter(com, con);
             DataTable dt = new DataTable();
             adpt.Fill(dt);
             ddlTablas.DataSource = dt;
             ddlTablas.DataBind();
             ddlTablas.DataTextField = "Turno";
             ddlTablas.DataValueField = "Turno";
             ddlTablas.DataBind();
             PopulateGridview();
         }
    
 void ddlNivel()
         {
             ddlTablas.DataSource = null;
             ddlTablas.DataBind();
             SqlConnection con = new SqlConnection(connectionString);
             string com = "Select DISTINCT Nivel from ee";
             SqlDataAdapter adpt = new SqlDataAdapter(com, con);
             DataTable dt = new DataTable();
             adpt.Fill(dt);
             ddlTablas.DataSource = dt;
             ddlTablas.DataBind();
             ddlTablas.DataTextField = "Nivel";
             ddlTablas.DataValueField = "Nivel";
             ddlTablas.DataBind();
             PopulateGridview();
         }

 protected void ddlCondicion_SelectedIndexChanged(object sender, EventArgs e)
         {
 if (ddlCondicion.SelectedValue == "Turno")
             {
                 ddlTurno();
             }
             if (ddlCondicion.SelectedValue == "Nivel")
             {
                 ddlNivel();
             }
 }

If I select first "Turno" in DDL and then "Nivel" the error message is:

'System.Data.DataRowView' does not contain a property with the name 'Turno'
But if first I select "Nivel", then "Turno" the message is:
'System.Data.DataRowView' does not contain a property with the name 'Nivel'

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered

Try removing the ddlTablas.DataBind() lines which are executed prematurely, before defining DataTextField and DataValueField.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.