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

    Model popup with list of employees with check box grid

    Hi,

    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.

    Regards,
    Kotireddy.
  • #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:ScriptManager>
    <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">
    </cc1:ModalPopupExtender>
    <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" />
    </asp:Panel>
    <!-- ModalPopupExtender -->
    </form>

    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

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

  • #766263
    Hi

    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">
    </ajax:ModalPopupExtender>
    <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">

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

    </asp:Panel>



    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);
    dAdapter.Fill(dtGrid);
    TxtName.Text = dtGrid.DefaultView[0]["Name"];

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

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

  • #766297
    Hi,

    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">
    </cc1:ModalPopupExtender>
    <asp:Panel ID="pnlPopup" runat="server" BackColor="White" Height="100px"
    Width="400px" Style="display: none">
    <table>
    <tr>
    <td>
    <asp:GridView Id="gv" runat="server" autogeneratecolumns="False"
    autogenerateselectbutton="True"
    selectedindex="1"
    onselectedindexchanged="gv_SelectedIndexChanged">
    <Columns>
    </Columns>
    </asp:GridView>
    </td>
    </tr>
    <tr>
    <td>
    <asp:HiddenField Id="hdnId" runat="server"/>
    <asp:Button Id="btnGet" runat="server" Text="Get Record" OnClick="btnGet_OnClick"/>
    </td>
    </tr>
    </table>
    </asp:Panel>


    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.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments