Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
validating checkbox which are not checked in the datagridview those record should not be save in the database.


In Save Button code as follows;

i written the above code in the save button.

for (int i = 0; i < DGv_Session.RowCount; i++)
{
try
{
if (DGv_Session[1, i].Value != null && DGv_Session[1, i].Value != "" && DGv_Session[2, i].Value != null && DGv_Session[2, i].Value != "" && DGv_Session[3, i].Value != null && DGv_Session[3, i].Value != "" && DGv_Session[4, i].Value != null && DGv_Session[4, i].Value != "")
{
sql = "insert into Tb_Session_Structure ([Cmn_Minor_code],[Days],[Session1],[Session2],[Session3],[Session4])";

sql = sql + " values('" + cb_Course_Code.Text + "',
'" + DGv_Session.Rows[i].Cells[0].Value.ToString() + "',
" + (Convert.ToBoolean(DGv_Session[1, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[2, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[3, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[4, i].Value) == true).ToString() + ")";
GFun.Error = "";
GFun.InsertAccessData(sql);
if (GFun.Error.ToString() != "")
{
MessageBox.Show(GFun.Error.ToString(), "Error");
return;
}
GFun.OleDbCon.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error");
return;
}
}


I am validating check box which are not checked in the datagridview that value not to be saved in the database.

Days 1 2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked

after enters the above records into the database and click the save button.

In the database records show as follows;

Days 1 2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked

but i want which checkbox which which are not checked in the datagridview do not be saved in the database.

I want the final output as follows after made entries and click the save button records in the database as follows;


Final ouput as follows;
Days 1 2
2 checkboxchecked checkboxchecked
Posted

1 solution

C#
var chkboxFlag=$("input:checkbox[id$=chkfrom]").is(":checked");

           if(!chkboxFlag)
           {
               return "Please select atleast 1 item from the list to add";
           }
 
Share this answer
 
Comments
CHill60 14-Mar-13 9:43am    
That doesn't look like c#???

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