Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 16-Nov-12 0:53am
v3
Comments
Anshu BM 15-Nov-12 2:45am    
show your code
S@53K^S 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

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.
 
Share this answer
 
Comments
Swathi Nagaraj 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900