Help binding my datagrid Nulls error
-
Where am i going wrong? i get this error "Object cannot be cast from DBNull to other types." code private void SetFilter(string strFilterExpression) { DataRow[] foundRows; DataTable table; try { table = dst.Tables["LeadsByRegion"]; foundRows = table.Select(strFilterExpression); table.Rows.Clear(); for (int i = 0 ; i <= foundRows.GetUpperBound(0); i++) { table.NewRow(); table.Rows.Add(foundRows[i]); } this.Panel1.Visible = false; this.Panel2.Visible = true; this.dtgFiltered.DataSource = table.DefaultView; this.dtgFiltered.DataBind(); } catch (Exception ex) { this.lblError.Text = ex.Message; } }:^)
-
Where am i going wrong? i get this error "Object cannot be cast from DBNull to other types." code private void SetFilter(string strFilterExpression) { DataRow[] foundRows; DataTable table; try { table = dst.Tables["LeadsByRegion"]; foundRows = table.Select(strFilterExpression); table.Rows.Clear(); for (int i = 0 ; i <= foundRows.GetUpperBound(0); i++) { table.NewRow(); table.Rows.Add(foundRows[i]); } this.Panel1.Visible = false; this.Panel2.Visible = true; this.dtgFiltered.DataSource = table.DefaultView; this.dtgFiltered.DataBind(); } catch (Exception ex) { this.lblError.Text = ex.Message; } }:^)
Hi there, IMO, you can debug your application to quickly figure out which method/code causes the casting error. I guess the DataBind method, if this is the case, you might want to use the template column in the datagrid so that you can use the data binding expression to do a checking on the data before binding it to the control.
-
Hi there, IMO, you can debug your application to quickly figure out which method/code causes the casting error. I guess the DataBind method, if this is the case, you might want to use the template column in the datagrid so that you can use the data binding expression to do a checking on the data before binding it to the control.