Click here to Skip to main content
Sign Up to vote bad
good
See more: MVC4
Hi All,
 
I am trying to implement a Grid with these functionalities insert, edit,delete,Filter,sort,search in MVC4.
 
I am unable to get the id of selected checkbox in gridview.
 
@using (Html.BeginForm("GridIndex", "Grid", FormMethod.Get, new { id = "detailForm" }))
    {
        <div>
            <table style="background-color: #ddeeee; width: 100%; padding: 4px; border-collapse: separate; border-spacing: 1px">
                <tr style="background-color: white">
                    <td>
                        <input id="inputcheckInsert" type="image" src="~/App_Themes/Default/Images/insert.jpg" />
                        @using (Html.BeginForm("GridIndex", "Grid", FormMethod.Get, new { id = "InsertForm" }))
                        {    @Html.AntiForgeryToken()
 

                        }
                    </td>
                    <td>
                        @using (Html.BeginForm("GridIndex", "Grid", FormMethod.Get, new { id = "click" }))
                        { 
                            @Html.AntiForgeryToken()
                            <input id="inputInsert" type="image" src="~/App_Themes/Default/Images/insert.jpg" />
                        }
                    </td>
                    <td>
                        @using (Html.BeginForm("Insert", "Grid", FormMethod.Post, new { id = "click" }))
                        { 
                            @Html.AntiForgeryToken()
                            <input id="inputEdit" type="image" src="~/App_Themes/Default/Images/Edit.jpg" />
                        }
                    </td>
                    <td>
                        @using (Html.BeginForm("Insert", "Grid", FormMethod.Post, new { id = "click" }))
                        { 
                            @Html.AntiForgeryToken()
                            <input id="inputDelete" type="image" src="~/App_Themes/Default/Images/Delete.jpg" />
                        }
                    </td>
                    <td colspan="2"></td>
                </tr>
                @*<tr>
                    <td>
                        <input id="inputInsert" type="image" src="~/App_Themes/Default/Images/insert.jpg" />
                    </td>
                </tr>*@
                <tr style="background-color: #00647C; color: White; text-align: center;">
                    <td></td>
                    <td>Person Code
                    </td>
                    <td>First Name
                    </td>
                    <td>Last Name
                    </td>
                    <td>Person Status Id
                    </td>
                    <td>Email
                    </td>
                </tr>
                @foreach (MVCSampleApplication.BusinessServiceReference.ExternalPersonBE external in Model)
                {                                
                    <tr style="background-color: white">
                        <td>
                            @Html.CheckBox("chBx")
                        </td>
                        <td>
                            @external.m_personCode
                        </td>
                        <td>
                            @external.m_firstName
                        </td>
                        <td>
                            @external.m_lastName
                        </td>
                        <td>
                            @external.m_lnPersonStatusId
                        </td>
                        <td>
                            @external.m_eMail
                        </td>
                    </tr>        
                }
            </table>
        </div>
    }
 
// contrler class
 
 public ActionResult GridIndex(FormCollection collection)
        {
            BusinessServiceReference.BusinessServiceClient service = new BusinessServiceReference.BusinessServiceClient();
            BusinessServiceReference.PersonBE[] PersonBeList = service.GetPersonList(0, 0, string.Empty, string.Empty);
 

            return View(externalPersonBeList);
        }
 
//when check box is selected and clicked edit button, I need corresponding column Id //to be passed to click event
 
public ActionResult imgBtEdit_Click(int p_id)
        {
            return RedirectToAction("Insert", "Default", p_id);
        }
 
How to know which checkbox is selected and how to get the datakeys?
 
Any suggestions or blogs?
 

Thank you
Swathi N
Posted 14 Nov '12 - 20:40
Edited 16 Nov '12 - 0:53

Comments
y5me211112 - 15 Nov '12 - 2:45
show your code
Sastry_kunapuli - 15 Nov '12 - 14:11
did you try using jquery on that ?try getting all items that are checked and get the value of "id" for each

1 solution

You need to give your checkboxes unique values or use jquery to filter based on a searchable parent node, to find which one is checked.
  Permalink  
Comments
Swathi Nagaraj - 20 Nov '12 - 5:11
Can you give littel more explantion how it can be done. since I tried using Jquery, I got many problems like content pages will not fire click events etc. $(#Id).Click(function(){ alert('called'}); But this same code will work in master page.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Rohan Leuva 220
1 Sergey Alexandrovich Kryukov 208
2 OriginalGriff 208
3 Abhinav S 168
4 Mahesh Bailwal 165
0 Sergey Alexandrovich Kryukov 8,474
1 OriginalGriff 6,714
2 CPallini 3,603
3 Rohan Leuva 2,853
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid