Click here to Skip to main content
11,431,011 members (68,872 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 21:40pm
Edited 16-Nov-12 1:53am
v3
Comments
y5me211112 at 15-Nov-12 2:45am
   
show your code
Sastry_kunapuli at 15-Nov-12 14:11pm
   
did you try using jquery on that ?try getting all items that are checked and get the value of "id" for each

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 20-Nov-12 5:11am
   
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)



Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100