locked
Gridview trick RRS feed

  • Question

  • User-1767698477 posted

    I have ths idea to add a checkbox onto each row of the gridview.  If you check a box though, it needs to be that when you go to check another box, it will check the new box but at the same time uncheck the previous box. The box serves as a selector and then there will be a button which when pushed will send the selected row for processing on the next page. I could just do this with a button, but I"m trying to conserve space in the gridview. Would javascript work for this purpose? Also, assuming this was possible, can a button be placed outside of the gridview to make the thing work?

    <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource2" OnRowDataBound="Gridview2_rowdatabound" OnRowCommand="Gridview2_Rowcommand"
    OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="3" ForeColor="Black"
    GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet"
    Caption="Loan Applications" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
    BorderWidth="1px">
    <AlternatingRowStyle BackColor="#CCCCCC" />
    <Columns>
    <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" />
    <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" />
    <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" />
    <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" />
    <asp:TemplateField ShowHeader="False" HeaderText="Create File">
    <ItemTemplate>
    <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUFile"
    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="3.2 File">
    <ItemTemplate>
    <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="" Enabled="True"></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="">
    <ItemTemplate>
    <asp:Button ID="EditApp" Text="Edit App" runat="server" OnCommand="Secondbuttoncommand"
    CommandName="Editapp" CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="">
    <ItemTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server" OnCommand="Thirdbuttoncommand"
    CommandName="Editapp" CommandArgument='<%#Bind("borssn")%>'></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <RowStyle />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
    </asp:GridView>

    Tuesday, April 14, 2020 5:12 AM

Answers

  • User1535942433 posted

    Hi sking,

    Accroding to your description,I'm guessing that you want to checked  the checkbox then click the button outside the gridview.After,you need to post the row data to another page.

    I suggest you could each the gridview then check if the chechbox is checked,If it is checked,get the row data.If you want to post the data to another page,you could use ajax.

    Could you tell us more details about your requirments?I create a demo.

    More details,you could refer to below codes:

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script>
            $(function () {
                $("[id*=GridView2] input[type=checkbox]").click(function () {
                    if ($(this).is(":checked")) {
                        $("[id*=GridView2] input[type=checkbox]").removeAttr("checked");
                        $(this).attr("checked", "checked");
                    }
                });
                $("#Button1").click(function () {
                    $("#GridView2 tr").each(function () {
                        var checkbox = $(this).find("input[type='checkbox']")
                        if (checkbox.is(":checked")) {
                            var row = $(this).closest("tr");
                             var message = "Row Index: " + (row[0].rowIndex - 1);
                            message += "\nFirst: " + row.find("td").eq(0).html();
                            message += "\nLast: " + row.find("td").eq(1).html();
                            message += "\nSSN: " + row.find("td").eq(2).html();
                            message += "\nApp Date: " + row.find("td").eq(3).html();
                            alert(message);
                        }
                    })
                })
            });
    
        </script>
    
    
     <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="GridView2_RowDataBound" OnRowCommand="GridView2_RowCommand" OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="3" ForeColor="Black"
                    GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet"
                    Caption="Loan Applications" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
                    BorderWidth="1px" DataSourceID="SqlDataSource2">
                    <AlternatingRowStyle BackColor="#CCCCCC" />
                    <Columns>
                        <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" />
                        <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" />
                        <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" />
                        <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" />
                        <asp:TemplateField ShowHeader="False" HeaderText="Create File">
                            <ItemTemplate>
                                <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUFile"
                                    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="3.2 File">
                            <ItemTemplate>
                                <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="" Enabled="True"></asp:HyperLink>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False" HeaderText="">
                            <ItemTemplate>
                                <asp:Button ID="EditApp" Text="Edit App" runat="server" OnCommand="Secondbuttoncommand"
                                    CommandName="Editapp" CommandArgument='<%#Bind("borssn") %>'></asp:Button>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False" HeaderText="">
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server"
                                    CommandName="Editapp"></asp:CheckBox>
                            </ItemTemplate>
                        </asp:TemplateField>
    
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <RowStyle />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />
                </asp:GridView>
                <asp:Button ID="Button1" runat="server" Text="Pass" />
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:aspnet-TestApplicationWithDatabase-20190820030542 %>" SelectCommand="SELECT * FROM [Bor]"></asp:SqlDataSource>

    Result:

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 15, 2020 9:03 AM

All replies

  • User475983607 posted

    I have ths idea to add a checkbox onto each row of the gridview.  If you check a box though, it needs to be that when you go to check another box, it will check the new box but at the same time uncheck the previous box.

    It's called a radio button.

    Tuesday, April 14, 2020 10:45 AM
  • User-1767698477 posted

    I don't like the appearance of a radio button.  I prefer more work to make a checkbox work.

    Tuesday, April 14, 2020 5:07 PM
  • User475983607 posted

    I don't like the appearance of a radio button.  I prefer more work to make a checkbox work.

    Please share your work.

    Tuesday, April 14, 2020 6:34 PM
  • User-1767698477 posted

    Please provide a solution. That's what this board is for?

    Tuesday, April 14, 2020 6:53 PM
  • User475983607 posted

    Please provide a solution. That's what this board is for?

    I did provide you a solution.  Use the right tool for the job which is a radio button.  You can use CSS to make the radio fancy if you like. 

    Below is a mutually exclusive checkbox by group.   I do not recommend this approach though.

        $("input:checkbox").click(function () {
            var group = "input:checkbox[name='" + $(this).prop("name") + "']";
            $(group).prop("checked", false);
            $(this).prop("checked", true);
        });

    Tuesday, April 14, 2020 7:21 PM
  • User-1767698477 posted

    If you think a radio button is the better solution, I will try this. I have found this article here that will do a mutually exclusive radio button in a gridview:

    https://www.aspdotnet-suresh.com/2010/12/how-to-make-single-radio-button.html

    What I'm unclear about is once you have this working, is it possible to use a single button outside of the gridview which when clicked will get me the index of the row with the selected radio button? Can you get the selected row from gridview eventargs by going to a button click event with a button outside the gridview?

    I have a button which is on the row in the gridview which is doing this via OnCommand="Editcommand". I'm thinking to do what I want, each time I select a different radio button, it just goes into a radiobuttoncommand sub in the code behind and store the row into a Session Session("selectedrow")=e.CommandArgument.ToString and then I can access this with my button outside the gridview. Is there another way? Every time you change your row with the radio button, the session variable gets changed. Is that nifty?

    Tuesday, April 14, 2020 9:44 PM
  • User1535942433 posted

    Hi sking,

    Accroding to your description,I'm guessing that you want to checked  the checkbox then click the button outside the gridview.After,you need to post the row data to another page.

    I suggest you could each the gridview then check if the chechbox is checked,If it is checked,get the row data.If you want to post the data to another page,you could use ajax.

    Could you tell us more details about your requirments?I create a demo.

    More details,you could refer to below codes:

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script>
            $(function () {
                $("[id*=GridView2] input[type=checkbox]").click(function () {
                    if ($(this).is(":checked")) {
                        $("[id*=GridView2] input[type=checkbox]").removeAttr("checked");
                        $(this).attr("checked", "checked");
                    }
                });
                $("#Button1").click(function () {
                    $("#GridView2 tr").each(function () {
                        var checkbox = $(this).find("input[type='checkbox']")
                        if (checkbox.is(":checked")) {
                            var row = $(this).closest("tr");
                             var message = "Row Index: " + (row[0].rowIndex - 1);
                            message += "\nFirst: " + row.find("td").eq(0).html();
                            message += "\nLast: " + row.find("td").eq(1).html();
                            message += "\nSSN: " + row.find("td").eq(2).html();
                            message += "\nApp Date: " + row.find("td").eq(3).html();
                            alert(message);
                        }
                    })
                })
            });
    
        </script>
    
    
     <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="GridView2_RowDataBound" OnRowCommand="GridView2_RowCommand" OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="3" ForeColor="Black"
                    GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet"
                    Caption="Loan Applications" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
                    BorderWidth="1px" DataSourceID="SqlDataSource2">
                    <AlternatingRowStyle BackColor="#CCCCCC" />
                    <Columns>
                        <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" />
                        <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" />
                        <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" />
                        <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" />
                        <asp:TemplateField ShowHeader="False" HeaderText="Create File">
                            <ItemTemplate>
                                <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUFile"
                                    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="3.2 File">
                            <ItemTemplate>
                                <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="" Enabled="True"></asp:HyperLink>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False" HeaderText="">
                            <ItemTemplate>
                                <asp:Button ID="EditApp" Text="Edit App" runat="server" OnCommand="Secondbuttoncommand"
                                    CommandName="Editapp" CommandArgument='<%#Bind("borssn") %>'></asp:Button>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False" HeaderText="">
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server"
                                    CommandName="Editapp"></asp:CheckBox>
                            </ItemTemplate>
                        </asp:TemplateField>
    
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <RowStyle />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />
                </asp:GridView>
                <asp:Button ID="Button1" runat="server" Text="Pass" />
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:aspnet-TestApplicationWithDatabase-20190820030542 %>" SelectCommand="SELECT * FROM [Bor]"></asp:SqlDataSource>

    Result:

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 15, 2020 9:03 AM
  • User-1767698477 posted

    Hello, I added the script to my head tags and added the button below the gridview,  but the alert is not triggering as in your screen recording.  How do you pass the row index of the selected row to the code behind? Do you use POST command to an array and use streamreader to read data? I was reading this page here:  https://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages

    <%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/templates/default1.master"
    CodeFile="Default.aspx.vb" Inherits="users_Default" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <title>Member Home Page</title>
    <script language="javascript" type="text/javascript">
    function SelectSingleRadiobutton(rdbtnid) {
    var rdBtn = document.getElementById(rdbtnid);
    var rdBtnList = document.getElementsByTagName("input");
    for (i = 0; i < rdBtnList.length; i++) {
    if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id) {
    rdBtnList[i].checked = false;
    }
    }
    }
    </script>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script>
    $(function () {
    $("[id*=GridView2] input[type=checkbox]").click(function () {
    if ($(this).is(":checked")) {
    $("[id*=GridView2] input[type=checkbox]").removeAttr("checked");
    $(this).attr("checked", "checked");
    }
    });
    $("#Button1").click(function () {
    $("#GridView2 tr").each(function () {
    var checkbox = $(this).find("input[type='checkbox']")
    if (checkbox.is(":checked")) {
    var row = $(this).closest("tr");
    var message = "Row Index: " + (row[0].rowIndex - 1);
    message += "\nFirst: " + row.find("td").eq(0).html();
    message += "\nLast: " + row.find("td").eq(1).html();
    message += "\nSSN: " + row.find("td").eq(2).html();
    message += "\nApp Date: " + row.find("td").eq(3).html();
    alert(message);
    }
    })
    })
    });

    </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="menu" class="container">
    </div>
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <form id="Form1" runat="server">
    <br />
    <table align="center" width="95%">
    <tr>
    <td align="left">
    Welcome : <b>
    <asp:Label ID="lblName" runat="server" Text="" ForeColor="#FFB30F"></asp:Label></b>
    </td>
    <td align="right">
    <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="changepassword.aspx">Change Password</asp:HyperLink>
    </td>
    </tr>
    <tr>
    <td align="left">
    <asp:LoginView ID="LoginView1" runat="server">
    <LoggedInTemplate>
    Logged in as :
    <asp:LoginName ID="LoginName1" runat="server" Font-Bold="True" />
    </LoggedInTemplate>
    <AnonymousTemplate>
    Your are not logged in.
    <br />
    Click the login link to sign in.
    </AnonymousTemplate>
    </asp:LoginView>
    </td>
    <td align="right">
    <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="edit_profile.aspx">Edit Profile</asp:HyperLink>
    </td>
    </tr>
    <tr>
    <td align="left">
    <asp:LoginStatus ID="LoginStatus1" runat="server" />
    </td>
    <td align="right">
    <asp:Button ID="NewApp" Text="Start New Application" runat="server" OnCommand="ClearSessionCommand"
    CommandName="ClearSession"></asp:Button>
    </td>
    </tr>
    </table>
    <hr size="4" width="95%" />
    <br />
    <center>
    <br />
    <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource2" OnRowDataBound="Gridview2_rowdatabound" OnRowCommand="Gridview2_Rowcommand"
    OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="3" ForeColor="Black"
    GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet"
    Caption="Loan Applications" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
    BorderWidth="1px">
    <AlternatingRowStyle BackColor="#CCCCCC" />
    <Columns>
    <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" />
    <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" />
    <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" />
    <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" />
    <asp:TemplateField ShowHeader="False" HeaderText="Create File">
    <ItemTemplate>
    <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUFile"
    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="3.2 File">
    <ItemTemplate>
    <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="" Enabled="True"></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="Revise">
    <ItemTemplate>
    <asp:Button ID="EditApp" Text="App" runat="server" OnCommand="Editcommand" CommandName="Editapp"
    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="Upload">
    <ItemTemplate>
    <asp:Button ID="Upload" Text="Docs" runat="server" OnCommand="Uploadcommand" CommandName="Upload"
    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="">
    <ItemTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server"
    CommandName="Editapp"></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <RowStyle />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
    </asp:GridView>
    <asp:Button ID="Button1" runat="server" Text="Pass" />
    </center>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnectionString %>"
    SelectCommand="SELECT [userid], [borfirst], [borlast], [borssn], [appcomplete] FROM [loanapps] WHERE ([userid] = @userid)">
    <SelectParameters>
    <asp:SessionParameter Name="userid" SessionField="userID" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    <br />
    </form>
    </asp:Content>

    Saturday, April 18, 2020 6:03 PM
  • User1535942433 posted

    Hi sking,

    Hello, I added the script to my head tags and added the button below the gridview,  but the alert is not triggering as in your screen

    Accroding to your description,as far as I think,you need to use $([id*=Button1]) instead of $("#Button1") in the content page.

    More detsils,you could refer to below codes:

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
        <title>Member Home Page</title>
        <script type="text/javascript">
            function SelectSingleRadiobutton(rdbtnid) {
                var rdBtn = document.getElementById(rdbtnid);
                var rdBtnList = document.getElementsByTagName("input");
                for (i = 0; i < rdBtnList.length; i++) {
                    if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id) {
                        rdBtnList[i].checked = false;
                    }
                }
            }
        </script>
    
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script>
            $(function () {
                $("[id*=GridView2] input[type=checkbox]").click(function () {
                    if ($(this).is(":checked")) {
                        $("[id*=GridView2] input[type=checkbox]").removeAttr("checked");
                        $(this).attr("checked", "checked");
                    }
                });
                $("[id*=Button1]").click(function () {
                    $("[id*=GridView2] tr").each(function () {
                        var checkbox = $(this).find("input[type='checkbox']")
                        if (checkbox.is(":checked")) {
                            var row = $(this).closest("tr");
                            var message = "Row Index: " + (row[0].rowIndex - 1);
                            message += "\nFirst: " + row.find("td").eq(0).html();
                            message += "\nLast: " + row.find("td").eq(1).html();
                            message += "\nSSN: " + row.find("td").eq(2).html();
                            message += "\nApp Date: " + row.find("td").eq(3).html();
                            alert(message);
                        }
                    })
                })
            });
    
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <div id="menu" class="container">
        </div>
    </asp:Content>
    <asp:Content ID="content3" ContentPlaceHolderID="contentbody" runat="server">
            <table align="center" width="95%">
                <tr>
                    <td align="left">Welcome : <b>
                        <asp:Label ID="lblName" runat="server" Text="" ForeColor="#FFB30F"></asp:Label></b>
                    </td>
                    <td align="right">
                        <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="changepassword.aspx">Change Password</asp:HyperLink>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <asp:LoginView ID="LoginView1" runat="server">
                            <LoggedInTemplate>
                                Logged in as :
                                <asp:LoginName ID="LoginName1" runat="server" Font-Bold="True" />
                            </LoggedInTemplate>
                            <AnonymousTemplate>
                                Your are not logged in.
                                <br />
                                Click the login link to sign in.
                            </AnonymousTemplate>
                        </asp:LoginView>
                    </td>
                    <td align="right">
                        <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="edit_profile.aspx">Edit Profile</asp:HyperLink>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <asp:LoginStatus ID="LoginStatus1" runat="server" />
                    </td>
                    <td align="right">
                        <asp:Button ID="NewApp" Text="Start New Application" runat="server" OnCommand="ClearSessionCommand"
                            CommandName="ClearSession"></asp:Button>
                    </td>
                </tr>
            </table>
            <hr size="4" width="95%" />
            <br />
            <center>
    <br />
    <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource1" OnRowDataBound="GridView2_RowDataBound" OnRowCommand="GridView2_RowCommand" OnPageIndexChanging="GridView2_PageIndexChanging"
    CellPadding="3" ForeColor="Black"
    GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet"
    Caption="Loan Applications" BackColor="White" BorderColor="#999999" BorderStyle="Solid"
    BorderWidth="1px">
    <AlternatingRowStyle BackColor="#CCCCCC" />
    <Columns>
    <asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" />
    <asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" />
    <asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" />
    <asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" />
    <asp:TemplateField ShowHeader="False" HeaderText="Create File">
    <ItemTemplate>
    <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUFile"
    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="3.2 File">
    <ItemTemplate>
    <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="" Enabled="True"></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="Revise">
    <ItemTemplate>
    <asp:Button ID="EditApp" Text="App" runat="server" OnCommand="Editcommand" CommandName="Editapp"
    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="Upload">
    <ItemTemplate>
    <asp:Button ID="Upload" Text="Docs" runat="server" OnCommand="Uploadcommand" CommandName="Upload"
    CommandArgument='<%#Bind("borssn") %>'></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ShowHeader="False" HeaderText="">
    <ItemTemplate>
    <asp:CheckBox ID="CheckBox1" runat="server"
    CommandName="Editapp"></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <RowStyle />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
    </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnet-TestApplicationWithDatabase-20190820030542 %>" SelectCommand="SELECT * FROM [loanapps]"></asp:SqlDataSource>
    <asp:Button ID="Button1" runat="server" Text="Pass" />
    </center>
    
            <br />
            <br />
            <br />
    </asp:Content>

    How do you pass the row index of the selected row to the code behind? Do you use POST command to an array and use streamreader to read data? I was reading this page here:  https://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages

    I suggest you could create a new thread about how to pass the row index of the selected row to the code behind using ajax.It will more  professionals to help you solve this problems.

    Best regards,

    Yijing Sun

    Monday, April 20, 2020 8:35 AM