Pass (Send) Checked (Selected) ASP.Net GridView Row to multiline TextBox (TextArea) using C# and VB.Net

Last Reply one month ago By pandeyism

Posted one month ago

I have a gridview with checkbox column, on when the checkbox column is checked, the rows will be transfered to a group of texboxes outside the gridview. 

using the jquery function, I was able to auto calculate the checked rows, however I have not been able to pass the other row values to the textboxes. 

Can anyone explain to me or point out what I'm doing wrong?

this the jquery function:

        <script type="text/javascript"> 
            $(function () {
                $('[id*=ItemChk1]').on('change', function () {
                    var value = 0;
                    $('[id*=ItemChk1]:checked').each(function () {
                        var row = $(this).closest('tr');
                        value = value + parseInt(row.find('[id*=lbRM]').html());
                    });
                    $('[id*=TotalLabel]').html(value); 
                    $('[id*=SumTotal]').val(value);
                });
            });
        </script>

 this the HTML code for the Gridview:

                <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
                    runat="server" AutoGenerateColumns="False" ShowFooter="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <asp:CheckBox ID="HeadChk1" runat="server" CssClass="HeadChk1" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="ItemChk1" runat="server" CssClass="ItemChk1" OnCheckedChanged="SaveEmployees"   />
                            </ItemTemplate>
                        </asp:TemplateField>
                       <%-- <asp:BoundField DataField="Id" HeaderText="Id">
                            <ItemStyle Width="30px" />
                        </asp:BoundField>--%>
                        <asp:TemplateField HeaderText="Servis">
                            <FooterTemplate>
                                Total
                            </FooterTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("cat") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("cat") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Harga">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("RM_biasa") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                               <%-- <asp:Label ID="TotalLabel" runat="server" Font-Bold="True" Font-Names="Palatino Linotype" CssClass="TotalLabel"
                                    Font-Size="14pt" ForeColor="Blue"></asp:Label>--%>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lbRM" CssClass="Label1" runat="server" Text='<%# Bind("RM_biasa") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Rawatan">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("treat") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Bind("treat") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Width="150px" />
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle BackColor="#3AC0F2" ForeColor="White" />
                </asp:GridView>

this is the C# code to pass the gridview row using selectedIdexChanged:

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow item in GridView1.Rows)
            {
                // check row is datarow
                if (item.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chk = (item.FindControl("ItemChk1") as CheckBox);
                    if (chk.Checked)
                    {
                       
                        string conn = servTxt.Text;
                    }
                }
            }
        }

 this is the C# code to pass the gridview row using checkChanged:

        protected void SaveEmployees(object sender, EventArgs e)
        {
            foreach (GridViewRow item in GridView1.Rows)
            {
                // check row is datarow
                if (item.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chk = (item.FindControl("ItemChk1") as CheckBox);
                    if (chk.Checked)
                    {
                       //textbox is id is servTxt
                        servTxt.Text = (Label)item.FindControl("Label3");
                    }
                }
            }
        }
This question does not have replies that have been liked.