ahmad tolpa
ahmad tolpa

Reputation: 33

Populate bootstrap modal from gridview edit link button

I have a gridview containing membership providers roles. enter image description here

With Link Button For editing and Link button for deleting.

I want to populate a modal with a text box inside it to save the role name as shown. enter image description here

I succeeded in populating the modal and binding the grid and all of that, but, how can I bind the txtRoleName in the modal with the role name of the row? Preferably without any postback if possible, or with postback if not.

Here is the code for the grid:

  <asp:GridView ID="grdRoles"
            CssClass="table table-bordered responsive"
            runat="server"
            GridLines="None"
            CellSpacing="-1" 
            AutoGenerateColumns="False"
            OnPageIndexChanging="grdRoles_PageIndexChanging"
            OnRowDataBound="grdRoles_RowDataBound"
            ShowFooter="True" ShowHeaderWhenEmpty="True" EmptyDataText="Empty !">
            <Columns>
                <asp:TemplateField HeaderText="#">
                    <ItemTemplate>
                        <asp:Label ID="lblRank" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Roles">
                    <ItemTemplate>
                        <asp:Label ID="lblRoleName" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Action">
                    <ItemTemplate>
                    <asp:LinkButton  ID="btnEdit" data-toggle="modal"  href="#EditModal" runat="server" CssClass="btn  icon-edit" />
                    <asp:LinkButton  ID="btnRemove" runat="server" CssClass="btn btn-danger remove"  Text="<i class=icon-remove></i>" />

                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>

        </asp:GridView>

And this is the code for the modal:

 <div id="EditModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Edit"
         aria-hidden="true">
   <div class="modal-header">
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
     <h3 id="helpModalLabel"><i class="icon-external-link"></i> Edit Role</h3>
   </div>
   <div class="modal-body">
     <div class="control-group">
       <div class="controls">
         <div class="input-prepend">
           <span class="add-on">Role Name</span>
           <asp:TextBox ID="txtRoleName" Text='<%# Bind("RoleId") %>' runat="server"></asp:TextBox>
         </div>
       </div>
       <div class="form-actions">
         <asp:Button ID="btnSave" type="submit" class="btn btn-primary" runat="server" Text="Save" />
       </div>
     </div>
   </div>
   <div class="modal-footer">
     <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
   </div>
 </div>

Upvotes: 1

Views: 10036

Answers (1)

Srav
Srav

Reputation: 45

I am using data property to send data to the modal:

<a id="edit" href="#dlgName" data-toggle="modal" role="button" 
   data-id="<%# DataBinder.Eval (Container.DataItem, "Id") %>" 
   data-IsPrimary ="<%# DataBinder.Eval(Container.DataItem, "IsPrimary") %>" >Edit</a>

And, retrieve the data using jQuery:

var Id = $('#edit').data('Id');
var isprimary = $('#edit').data('IsPrimary');

Upvotes: 1

Related Questions