Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
I have a datatable having a 5 rows and 4 columns

this 5 rows and 4 columns should fill


Datatable Name is dtexam

Should be like this:
Name  Mark1 Mark2 Mark3

V1     20    20     20   <----

v2     30    30     10   <----

v3     50    40     10   <----

v4     50    20     10   <----

v5     40    30     50   <----




shouldnot be like this:

Name  Mark1 Mark2 Mark3

V1     20           20

v2     30           10

v3     50    40     10

v4     50    20

v5     40           50


   For row validation i did like this..

   if(dtexams.rows.count<=0)
   {
      obal.mess("Please fill marks");
   }

  for this Scenario it checking rowwise correct.

  i want columnwise also to validate..
Posted

1 solution

It would be better if you validate this from the UI control itself instead of looping in datatable...


Or else you can try something like this


C#
for (int i = 0; i < dt.Rows.Count; i++)
{
    if (!ValidateMarks(dt.Rows[i]))
    {
        //Please enter valid mark
    }
                   
}


where ValidateMarks Method will look like

C#
private bool ValidateMarks(System.Data.DataRow dRow)
{
    if (dRow["Mark1 "] != null || dRow["Mark1 "] != DBNull.Value || dRow["Mark1 "].ToString().Trim() != "")
    {
        return true;
    }
    return true;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900