Well in this scenario I recommend you to read every cell from every row that you have, and when you find a value in any cell you need to make sure that there are values for the other cells.
I did a little sample for you, I hope this help you with your problem.
At first I created this entity to fill my gridview:
public class MyEntity
{
public string ID { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
}
This is the code on my aspx page
<form id="form1" runat="server">
<div>
<asp:GridView ID="grvData" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="ID" >
<ItemTemplate >
<asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:TextBox ID="txtLastName" runat="server" Text='<%# Eval("LastName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnValidate" runat="server" Text="Validate" OnClick="btnValidate_Click" />
<br />
<asp:Label ID="lblMessage" runat="server" ForeColor="Red" Text="">
</asp:Label>
</div>
</form>
Then on my code behind
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<MyEntity> data = GenerateData();
this.grvData.DataSource = data;
this.grvData.DataBind();
}
}
protected void btnValidate_Click(object sender, EventArgs e)
{
int columns = this.grvData.Columns.Count - 1;
foreach (GridViewRow row in this.grvData.Rows)
{
int count = columns;
TextBox tbName = row.Cells[1].FindControl("txtName") as TextBox;
TextBox tbLastName = row.Cells[2].FindControl("txtLastName") as TextBox;
if (!string.IsNullOrWhiteSpace(tbName.Text))
{
count--;
}
if (!string.IsNullOrWhiteSpace(tbLastName.Text))
{
count--;
}
if (count != columns && count != 0)
{
this.lblMessage.Text = "Invalid input, you need to supply data for every field.";
break;
}
}
}
private List<MyEntity> GenerateData()
{
List<MyEntity> list = new List<MyEntity>();
for (int i = 0; i < 5; i++)
{
MyEntity entity = new MyEntity() { ID = Guid.NewGuid().ToString() };
list.Add(entity);
}
return list;
}
}
As you can see is pretty simple, I would not recommend you to use this approach if you are loading too many records with many columns, because that could affect performance, but in your case I think this should works.
PS. My answer is with visual C#, because when I read it you did not mention the language, and now you just changed it.