You must Sign In to post a response.
  • Category: ASP.Net MVC

    Model popup with list of employees with check box grid


    I have to show the model popup with the list of employees in grid with check box. The selected employee ids should come back to main view.

    Any one suggest the good link or post me sample code to implement.

  • #766255
    You need to use ASP.Net AJAX ModalPopupExtender control. for that You will need to register the AJAX Control Toolkit Library by putting the following line just below the @PageDirective

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    //then add modal popup extender on page
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" />
    <!-- ModalPopupExtender -->
    <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="btnShow"
    CancelControlID="btnClose" BackgroundCssClass="modalBackground">
    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">
    This is an ASP.Net AJAX ModalPopupExtender Example<br />
    <asp:Button ID="btnClose" runat="server" Text="Close" />
    <!-- ModalPopupExtender -->

    now you can put gridview with ItemTemplate and Template columns in ModalPopupExtender once you have put checkboxes in gridview, you can simple select them getch them to page using session object

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766263

    try this code client Side

    <asp:ScriptManager ID="dd" runat="server"></asp:ScriptManager>

    <asp:Button ID="Btn1" runat="server" OnClick="Btn1_Click" Text="Show Popup" />

    <asp:Button ID="btnShowPopup" runat="server" style="display:none" />

    <ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
    CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
    <asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="269px" Width="400px" style="display:none">

    <asp:GridView ID="gvDetails" runat="server" DataKeyNames="ID"
    AutoGenerateColumns="False" OnSelectedIndexChanged="gvDetails_SelectedIndexChanged">

    <asp:TemplateField HeaderText="First Name" SortExpression="FirstName">
    <asp:Label ID="lblFname" runat="server" Text='<%#Eval("FirstName")%>'/>
    <asp:TemplateField HeaderText="Last Name" SortExpression="LastName">
    <asp:Label ID="lblLname" runat="server" Text='<%#Eval("LastName")%>'/>
    <asp:TemplateField HeaderText="Location" SortExpression="Location">
    <asp:Label ID="lblLocation" runat="server" Text='<%#Eval("Location")%>'/>


    Server Side

    DataTable dtGrid = new DataTable();
    int id = Convert.ToInt32(gvDetails.DataKeys[0].Values[0]);
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    string strSelect = "SELECT FirstName,LastName,Location FROM Details where Id="+id ;
    SqlCommand cmd = new SqlCommand(strSelect, con);
    SqlDataAdapter dAdapter = new SqlDataAdapter(cmd);
    TxtName.Text = dtGrid.DefaultView[0]["Name"];

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766297

    If you want to get the selected records from modal popup and use that in your main view then my suggestion is go through AJAX modal popup extender control and show your modal dialog and design gridview inside that dialog and based on row selection you need to get the selected Id of that particular row,

    Refer below sample this might be helpful to you.

    <asp:Button ID="btnShowPopup" Text="Show Popup" runat="server" Style="display: none" />
    <cc1:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnShowPopup"
    PopupControlID="pnlPopup" BackgroundCssClass="modalBackground">
    <asp:Panel ID="pnlPopup" runat="server" BackColor="White" Height="100px"
    Width="400px" Style="display: none">
    <asp:GridView Id="gv" runat="server" autogeneratecolumns="False"
    <asp:HiddenField Id="hdnId" runat="server"/>
    <asp:Button Id="btnGet" runat="server" Text="Get Record" OnClick="btnGet_OnClick"/>

    and onSelectedIndexChanged event assign the index value to hidden field and while click on GetRecord button pass the hiddenfield value to main view.

    Protected void gv_SelectedIndexChanged(Object sender, EventArgs e)
    GridViewRow row = gv.SelectedRow;
    hdnId.Value= row.Cells[2].Text ;
    Protected void btnGet_OnClick(Object sender, EventArgs e)
    //pass hidden field value to main view

    Hope this will helpful to you....

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments