<asp:GridView ID="GRVItem" DataKeyNames="ItemCode,ItemName" runat="server" Font-Names="Calibri" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" AllowPaging="True" PageSize="5" ShowHeader="true" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" Width="1000px" padding-top=" 70px;" AutoGenerateColumns="false" > <HeaderStyle BorderColor="Gray" BorderStyle="Solid" Font-Bold="true" BackColor="#76C3FD" /> <Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="chkAll" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckChanged" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chk" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckChanged" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="Item Code" DataField="ItemCode" ReadOnly="true"/> <asp:BoundField HeaderText="Item Name" DataField="ItemName" ReadOnly="true" /> <asp:BoundField HeaderText="In Stack" DataField="OnHand" ReadOnly="true" /> <asp:TemplateField HeaderText="Quantity"> <EditItemTemplate> <asp:TextBox ID="txtQuantity" runat="server" /> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Protected Sub CheckBox_CheckChanged(ByVal sender As Object, ByVal e As EventArgs) GetSelectedRows() BindSecondGrid() End Sub Protected Sub BindSecondGrid() Dim dt As DataTable = DirectCast(ViewState("GetRecords"), DataTable) GridView1.DataSource = dt GridView1.DataBind() End Sub Private Sub GetSelectedRows() Dim dt As DataTable If ViewState("GetRecords") IsNot Nothing Then dt = DirectCast(ViewState("GetRecords"), DataTable) Else dt = CreateDataTable() End If For i As Integer = 0 To GRVItem.Rows.Count - 1 Dim chk As CheckBox = DirectCast(GRVItem.Rows(i).Cells(0).FindControl("chk"), CheckBox) If chk.Checked Then dt = AddRow(GRVItem.Rows(i), dt) Else dt = RemoveRow(GRVItem.Rows(i), dt) End If Next ViewState("GetRecords") = dt End Sub Private Function AddRow(ByVal gvRow As GridViewRow, ByVal dt As DataTable) As DataTable Dim dr As DataRow() = dt.Select("ItemCode = '" _ & gvRow.Cells(1).Text & "'") If dr.Length <= 0 Then dt.Rows.Add() dt.Rows(dt.Rows.Count - 1)("ItemCode") = gvRow.Cells(1).Text dt.Rows(dt.Rows.Count - 1)("ItemName") = gvRow.Cells(2).Text dt.Rows(dt.Rows.Count - 1)("Quantity") = gvRow.Cells(4).Text ' Hear is not copy the Value of Quantity .this is the textbox in gridview dt.AcceptChanges() End If Return dt End Function Private Function RemoveRow(ByVal gvRow As GridViewRow, ByVal dt As DataTable) As DataTable Dim dr As DataRow() = dt.Select("ItemCode = '" _ & gvRow.Cells(1).Text & "'") If dr.Length > 0 Then dt.Rows.Remove(dr(0)) dt.AcceptChanges() End If Return dt End Function Private Function CreateDataTable() As DataTable Dim dt As New DataTable() dt.Columns.Add("ItemCode") dt.Columns.Add("ItemName") dt.Columns.Add("Quantity") dt.Columns.Add("Price") dt.AcceptChanges() Return dt End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)