Click here to Skip to main content
15,884,892 members

unable to get the id of selected checkbox in gridview MVC4

Swathi Nagaraj asked:

Open original thread
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
Tags: MVC4

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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