Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a gridview like below in my view
<table id="list" cellspacing="0" cellpadding="0">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.UserName)
        </th>
        @*<th>
            @Html.DisplayNameFor(model => model.Password)
        </th>*@
        <th>
            @Html.DisplayNameFor(model => model.Address)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.MobileNumber)
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.UserName)
            </td>
            @* <td>
            @Html.DisplayFor(modelItem => item.Password)
        </td>*@
            <td>
                @Html.DisplayFor(modelItem => item.Address)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.MobileNumber)
            </td>
            <td>
                @*@Html.ActionLink("Edit", "../SaveData/SaveData", new { id = item.UserID }) |*@
                @Html.ActionLink("Edit", "Details", new { id = item.UserID }, new { @class = "details-modal", @onclick = "javascript:foo();" })
                @Html.ActionLink("Delete", "Delete", new { id = item.UserID })
            </td>
        </tr>
    }


when click on the action link a popup is showing. the code used in linke below

@{
var user = (User)ViewData["userdetails"];
//if (ViewData["userdetails"] != null)
//{
// ViewBag.username = @user.UserName;
//}
//ViewBag.userdata="fdfdsfsdfsdfsd";
//ViewBag.userdata=@user.UserName;
@Html.ValidationSummary(true);

<input type="text" id="user" />

@Html.LabelFor(model => @user.UserName)


@Html.EditorFor(model => @user.UserName)
@Html.ValidationMessageFor(model => @user.UserName)


@Html.LabelFor(model => @user.Password)


@Html.Password("Password")
@Html.ValidationMessageFor(model => @user.Password)


@Html.LabelFor(model => @user.Address)


@Html.EditorFor(model => @user.Address)
@Html.ValidationMessageFor(model => @user.Address)


@Html.LabelFor(model => @user.MobileNumber)


@Html.EditorFor(model => @user.MobileNumber)
@Html.ValidationMessageFor(model => @user.MobileNumber)


<input type="submit" value="Create" />



}

<script type="text/jscript">
$('#my-dialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
modal: true
});

$('.details-modal').click(function () {
//var username = '@ViewBag.username';
//document.getElementById('user').value = username;

var theURL = $(this).attr('href');
$('#my-dialog').load(theURL, function () {
$(this).dialog('open');

});

return false; // ensures the browser is not redirected to the link's URL
});

i want to populate each textbox with the corresponding data in the clicked row. how can i possible?
Posted
Comments
Jameel VM 8-Jul-13 3:02am    
what's the pblm?

1 solution

By using jQuery you can get all the cell values of particular row
JavaScript
This would get you the index of the clicked row, starting with one:

$('#thetableId').find('tr').click( function(){
  alert('You clicked row '+ ($(this).index()+1) );
});
If you want to return the number stored in that first cell of each row:

$('#thetable').find('tr').click( function(){
  var row = $(this).find('td:first').text();
  alert('You clicked ' + row);
});


Hope this helps
 
Share this answer
 
Comments
Kunjammu 8-Jul-13 3:48am    
i have an actionlick in each row. when click on that everything should happen
Jameel VM 8-Jul-13 5:34am    
when the page first load bind the row index as any attribute to a particular cell.
Jameel VM 8-Jul-13 5:40am    
create a function and pass the index as parameter and put the code that i have posted for getting the row details

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