I have a gridview with template column for edit button, which opens a bootstrap modal dialog with data populated without a postback.
Here's the Gridview :
<asp:GridView ID="gvLocAddresses" runat="server" CssClass="table table-bordered table-striped table-condensed"
GridLines="None" AllowSorting="false" PageSize="25" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="Edit" >
<ItemTemplate>
<a id="editLocAddress" href="#dlgLocAddress" data-toggle="modal" role="button" onclick="EditLocAddress();"
data-id="<%# DataBinder.Eval (Container.DataItem, "Id") %>"
data-IsPrimary = "<%# DataBinder.Eval(Container.DataItem, "IsPrimary") %>"
data-Address1 = "<%# DataBinder.Eval(Container.DataItem, "Address1") %>"
data-Address2 = "<%# DataBinder.Eval(Container.DataItem, "Address2") %>"
data-City = "<%# DataBinder.Eval(Container.DataItem, "City") %>"
><i class="icon-edit"></i></a>
</ItemTemplate>
</asp:TemplateField>
This is the modal dialog :
<div id="dlgLocAddress" class="modal hide fade" tabindex="-1" role="dialog"
aria-hidden="true" style="width: 475px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×</button>
<h3 id="dlgAddLocAddrLBL">Add Address</h3>
</div>
<div class="modal-body">
<div class="row">
<div class="span2 text-right">
<label for="txtAddrLine1">Address Line1</label>
</div>
<div class="span3">
<input id="txtAddrLine1" type="text" class="text ui-widget-content ui-corner-all" />
</div>
</div>
<div class="row">
<div class="span2 text-right">
<label for="txtAddrLine2">Address Line2</label>
</div>
<div class="span3">
<input id="txtAddrLine2" type="text" class="text ui-widget-content ui-corner-all" />
</div>
</div>
<div class="row">
<div class="span2 text-right">
<label for="txtCity">City</label>
</div>
<div class="span3">
<input id="txtCity" type="text" class="text ui-widget-content ui-corner-all" />
</div>
</div>
And Heres my Jquery function :
function EditLocAddress() {
var $editLAddr = $('#editLocAddress'),
addressid = $editLAddr.data('id'),
$(".modal-body #txtAddrLine1").val($editLAddr.data('address1'));
$(".modal-body #txtAddrLine2").val($editLAddr.data('address2'));
$(".modal-body #txtCity").val($editLAddr.data('city'));
}
Now, when I click Edit, the dialog button always populates the first row. I am new to Jquery and client side programming. Can someone please help.
Thanks, Sri