Click here to Skip to main content
15,894,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir ,

i have five checkboxes. Checkboxes place into table column. like
first column first checkbox, second column into second, third checkboxes row wise. and finally third column forth, fifth checkboxes. following:
----------------------------------------------------------------------------------
column 1 | Column 2 | column3
--------------------------------------------------------------------------------
Checkbox1 | Checkbox2 | Checkbox4
| checkbox3 | checkbox5

----------------------------------------------------------------------------
When i checked checkbox1 , checkbox3 and Checkbox5 save checkbox3 ,Checkbox5 value into checkbox1 and database table refresh page unchecked all checkboxes then after click checkbox1 automatically checked checkboxes(checkbox3 ,Checkbox5 ).


My Controller code:=



XML
public ActionResult ModuleMapping()
        {
            WFID = Convert.ToInt32(Request["wfid"]);
            string mysql = "select *  from modules where parentid="+ WFID;
             db.Query = mysql;
             DataTable dt2 = db.GetTable();
             ArrayList list = new ArrayList();
             foreach (DataRow dr in dt2.Rows) // dt- DataTable
             {
                 list.Add(dr);
             }

            string itemString = "<table width='100px'><tr>";
            string itemString1 = "";

            Int32 ParentID = 0;
            Int32 ParentValue = 0;
            Int32 LevelID = 0;
            Int32 Mcounter = 0;
            Int32 LastValue = 0;
            foreach (DataRow dr in list)
            {
                LevelID += 1;
                itemString1 += "<input type='hidden' id='LastValue" + LevelID + "' value=0>\n";

                itemString += "<td valign='top'><table width='200px'>";
                itemString += "<tr><td><b>" + dr["Title"] + "<b><td></tr>";
                mysql = "select Id,title  from t" + dr["ID"];
                db.Query = mysql;
                DataTable dt=db.GetTable();
                ArrayList list2 = new ArrayList();
                foreach (DataRow dr2 in dt.Rows) // dt- DataTable
                {
                    list2.Add(dr2);
                }
                Mcounter = 0;

                foreach (DataRow item in list2)
                {
                    Mcounter += 1;

                    string tt1 = item["ID"].ToString();
                    string tt2 = item["ID"].ToString();
                    string HidVar = Mcounter + "$" + LevelID;
                    itemString += "<tr><td>";
                    itemString += "<input type='hidden' id='Child$" + HidVar  + "' Value='" + item["ID"] + "'>";
                    itemString += "<input type='checkbox' name=\"chkcountry\" id='chk$" + HidVar + "' value='' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'><a href='#' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'>" + item["Title"] + "</a>";
                    //itemString += "<input type='checkbox' id='chk$" + ParentID + "$" + itemMain.ID + "$" + item.ID + "$" + LevelID + "' value=''><a href='#' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + LevelID + ");'>" + item.Title + "</a>";
                    itemString += "</td></tr>";
                }
                ParentID = Convert.ToInt32(dr["ID"]);
                itemString += "</td></table>";
            }



            itemString += "</tr></table>";

            ViewData["mystring"] = (itemString + itemString1);
            return View();
        }



My ModuleMapping.cshtml code:=


@{
ViewBag.Title = "ModuleMapping";
Layout = "~/Views/Shared/MobileRozer.cshtml";
Int32 WorkFlowID = Convert.ToInt32(ViewData["data"]);
}
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>

<script type="text/javascript">

var results = new Array();
function clickme(HidVar, txt, txt1, Mcounter, LevelID, ignore, rb) {

var ChildValue = document.getElementById("Child$" + HidVar).value;
var chk = document.getElementById("chk$" + HidVar).checked;
// alert(chk);


// var chk1 = document.getElementById("chk$" + HidVar).checked = true;

if (LevelID > 1)
{
for (index = 1; index < 4; ++index) {
if (Mcounter != index && document.getElementById("chk$" + HidVar).checked== false)
{
document.getElementById("chk$" + index + "$" + LevelID).disabled = true ;
}
if (document.getElementById("chk$" + HidVar).checked == false)
{
document.getElementById("chk$" + index + "$" + LevelID).disabled = false;
}
}
}





document.getElementById("LastValue" + LevelID).value = ChildValue;

var ParentValue = 0;
if (LevelID > 1) {
ParentValue = document.getElementById("LastValue" + (LevelID - 1)).value;
}
else {

ParentValue = document.getElementById("LastValue" + (LevelID)).value;
}

// function checkbox(me, group) {
//load History
//alert("Level ID: " + LevelID);
//Remove Status - Unchecked all the value for a child Level
var OneToOne = 1;
for (index = 0; index < results.length; ++index) {
if (results[index][2] >= (LevelID + 1)) {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = false;
//document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).disabled = true;
}
}


//One to One Checking
var OneToNE = 0;
var ChildStatus = 0;
//Setting Status - checked all the value for a child Level
for (index = 0; index < results.length; ++index) {
if (results[index][0] == ChildValue && results[index][2] >= (LevelID + 1)) {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = true;
if (OneToNE == 0) {
//document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).disabled = false;
}
ChildStatus = 1
}

}

//Checking if exist
var exist = 0;
for (index = 0; index < results.length; ++index) {
if (results[index][0] == ParentValue && results[index][1] == ChildValue && results[index][2] == LevelID && results[index][4] == Mcounter) {
exist = 1;
if (chk == false && ChildStatus == 0) {
removeByIndex(results, index);
}
else {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = true;

}
}
}

//IF not exist then storing in the array
if (exist == 0) {
results.push([ParentValue, ChildValue, LevelID, HidVar, Mcounter, "-"]);
}


document.getElementById("Button1").click = results;

var fk = document.getElementById("Button1").click;
alert(fk);
}

function removeByIndex(arr, index) {
arr.splice(index, 1);

}


$(document).ready(function () {
$('#Button1').click(function ()
{
var favorite = [];
$.each($(results), function ()

{
favorite.push($(this).val());
});
alert("My favourite sports are: " + favorite.join(", "));
});
});

</script>

<form name="addForm">



@Html.Raw(ViewData["mystring"]);

<input id="Button1" type="button" value="Save" />
</form>
Posted
Updated 12-Jan-15 2:29am
v2
Comments
CHill60 12-Jan-15 8:25am    
What have you tried?
Nishant.Chauhan80 12-Jan-15 8:26am    
yes..
ZurdoDev 12-Jan-15 8:27am    
This is not clear at all.
Praveen Kumar Upadhyay 12-Jan-15 9:51am    
Buddy, no one is gonna read so long code. Be specific and put only related codes.

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