Please see my code below and tell me where I am going wrong.
case "particulars.aspx": dt = JobCardManager.GetParticularsByJobId(id); hidJobId.Value = id.ToString(); if (dt != null && dt.Rows.Count > 0) { gvParticulars.DataSource = dt; gvParticulars.DataBind(); } else { **dt.Rows.Add(dt.NewRow());** gvParticulars.DataSource = dt; gvParticulars.DataBind(); int TotalColumns = gvParticulars.Rows[0].Cells.Count; gvParticulars.Rows[0].Cells.Clear(); gvParticulars.Rows[0].Cells.Add(new TableCell()); gvParticulars.Rows[0].Cells[0].ColumnSpan = TotalColumns; gvParticulars.Rows[0].Cells[0].Text = "No Record Found"; } ddlJobs.Enabled = false; gvParticulars.ShowFooter = true; break;
I want to ensure that in case dt has no lines, I need to display a new line in the footer, the controls are already added to the footer. My insert update and adding a new process are done from the grid itself.
So, if my datatable is null, then in the highlighted row I get the error: "Column does not allow null." Where in the database all columns have Allow Null flags. Please, help.
[Update]
I do not retrieve the primary key in the request. Editable parts of the table only.
source share