Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am displaying the data in a table with the help of foreach loop. the table contains a checkbox. suppose in first row i have checked the checkbox then only the data of first row will be inserted in the table. how to do that?

What I have tried:

view:
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>RELATION</th>
<th>NAME</th>
<th>CELL NO.</th>
<th>EMAIL</th>
<th>IMAGE</th>
<th>NEW CEL NO.</th>
<th>NEW EMAIL ID</th>
<th>NEW IMAGE</th>
<th>SELECT</th>
</tr>
</thead>


@foreach (var item in Model)
{
<tbody>
<tr>
<td>
@Html.DisplayFor(modelItem => item.relation)
</td>
<td>
@Html.DisplayFor(modelItem => item.mname)

</td>
<td>
@Html.DisplayFor(modelItem => item.oldcellno)
</td>
<td>
@Html.DisplayFor(modelItem => item.oldemail)
</td>
<td>
@Html.DisplayFor(modelItem => item.oldimage)
</td>
<td>
@Html.DisplayFor(modelItem => item.newcellno)
</td>
<td>
@Html.DisplayFor(modelItem => item.newemail)
</td>
<td>
@Html.DisplayFor(modelItem => item.newimage)
</td>
<td>
<input type="checkbox" value ="True" name="myCheckbox" class="myCheckbox" id="SmsBirthdayYN" onclick="selectOnlyThis(this)" />
</td>
</tr>
</tbody>
}
</table>
</div>

<input type="submit" name="btnname" value="AUTHORIZE" class="btn btn-primary">
<input type="reset" name="btnname" value="CLEAR" class="btn btn-primary">

}

controller:

namespace CHSWeb.Areas.Club.Controllers
{
public class ProfileAuthorizeController : Controller
{
BLLProfile BP = new BLLProfile();
// GET: ProfileAuthorize
public ActionResult Index(string autoid)
{
var data = BP.AuthorizeData(autoid);
return View(data);
}


[HttpPost]
public ActionResult Index(FormCollection form, MemberProfile FM)
{
string mcode = Session["LoginUserName"].ToString();


// FM.MemPro = BP.Viewold(mcode);
var data = BP.AuthorizeData(mcode);

ProfileView PV = new ProfileView();

string btnName = form["btnname"];
var records = new MemberProfile();
string flag = "";

var checkbox = form.GetValues("myCheckbox");

foreach (string item in checkbox)
{
switch (btnName)
{
case "AUTHORIZE":
PV.AUTHORIsed = "Y";
flag = BP.AuthorizeProfile(PV);
ViewBag.Message = "Record Authorized Successfully";
break;
}
}

if (flag == "success")
{
ViewBag.HideClass = "alert alert-success";
ModelState.Clear();
}
else
{
ViewBag.HideClass = "alert alert-danger";
ViewBag.Message = "Error! Record Not Authorized";
}
return View(data);
}
}
}
Posted
Comments
Richard Deeming 8-May-17 10:49am    
Rather than giving the checkbox a value of "True", you need to give it a value that you can use to identify the selected row.
Member 12561119 11-May-17 3:13am    
Thanks Richard

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