Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<div>
           <table>
               <tr>
                   <td colspan="2" align="center">
                       <asp:Label ID="Label1" runat="server" Text="Send Data From 1 Grid to Another Grid of Next Page"
                           Font-Bold="true" Font-Size="Large" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>
                   </td>
               </tr>
               <tr>
                   <td colspan="2" align="center">
                       <asp:Button ID="Button1" runat="server" Text="Pass Data to Second Page" Font-Names="Verdana"
                           Width="213px" BackColor="Orange" Font-Bold="True" OnClick="Button1_Click" Style="height: 26px" />
                   </td>
               </tr>
               <tr>
                   <td colspan="2" align="center">
                       <asp:GridView ID="GridView1" runat="server" CssClass="grid" BackColor="LightGoldenrodYellow"
                           BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None"
                           AutoGenerateColumns="false">
                           <AlternatingRowStyle BackColor="PaleGoldenrod" />
                           <FooterStyle BackColor="Tan" />
                           <HeaderStyle BackColor="Tan" Font-Bold="True" />
                           <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
                           <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
                           <SortedAscendingCellStyle BackColor="#FAFAE7" />
                           <SortedAscendingHeaderStyle BackColor="#DAC09E" />
                           <SortedDescendingCellStyle BackColor="#E1DB9C" />
                           <SortedDescendingHeaderStyle BackColor="#C2A47B" />
                           <Columns>
                               <asp:TemplateField HeaderText="DocketNo">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="DocketNo" Text='<%# Bind("DocketNo") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                               <asp:TemplateField HeaderText="Date">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="Date" Text='<%# Bind("Date") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                               <asp:TemplateField HeaderText="Branch">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="Branch" Text='<%# Bind("Branch") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                               <asp:TemplateField HeaderText="To">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="To" Text='<%# Bind("To") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                               <asp:TemplateField HeaderText="PKG">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="PKTS" Text='<%# Bind("PKTS") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                               <asp:TemplateField HeaderText="Act Wt">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="ActWt" Text='<%# Bind("ActWt") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                               <asp:TemplateField HeaderText="Charge Wt">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="ChargeWt" Text='<%# Bind("ChargeWt") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                               <asp:TemplateField HeaderText="Mode">
                                   <ItemTemplate>
                                       <asp:Label runat="server" ID="Basis" Text='<%# Bind("Basis") %>'>
                                       </asp:Label></ItemTemplate>
                               </asp:TemplateField>
                           </Columns>
                       </asp:GridView>
                   </td>
               </tr>
           </table>


The C# for the grid view is as follows:
C#
  if (!IsPostBack)
        {
            Bind();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SendGridInfo();
    }
    private void Bind()
    {
        con.Open(); SqlCommand cmd = new SqlCommand("select *  FROM CreateDocket WHERE Branch='" + lbl_sal.Text+ "';  ", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet(); da.Fill(ds); con.Close();
        GridView1.DataSource = ds; GridView1.DataBind();
    }
    private void SendGridInfo()
    {
        DataTable dt = new DataTable();
        DataRow dr; dt.Columns.Add(new System.Data.DataColumn("DocketNo", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Date", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Branch", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("To", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("PKG", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("ActWT", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("ChargeWt", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Basis", typeof(String)));
        foreach (GridViewRow row in GridView1.Rows)
        {
            Label DocketNo = (Label)row.FindControl("DocketNo");
            Label Date = (Label)row.FindControl("Date");
            Label Branch = (Label)row.FindControl("Branch");
            Label To = (Label)row.FindControl("To");
            Label PKTS = (Label)row.FindControl("PKTS");
            Label ActWt = (Label)row.FindControl("ActWt");
            Label ChargeWt = (Label)row.FindControl("ChargeWt");
            Label Basis = (Label)row.FindControl("Basis");
            dr = dt.NewRow(); dr[0] = DocketNo.Text; dr[1] = Date.Text; dr[2] = Branch.Text; dr[3] = To.Text; dr[4] = PKTS.Text; dr[5] = ActWt.Text; dr[5] = ChargeWt.Text; dr[5] = Basis.Text; dt.Rows.Add(dr);
        }
        Session["GridData"] = dt; Response.Redirect("ReciveChallan.aspx");
    }
}


what I want id I want To Add A radio button and a text box to the gridview and I want to save it in A new table.the selected item will be saved in a new table called challan. Selected item will be passed to a second page.
Posted
Updated 24-Nov-14 17:25pm
v2
Comments
Member 11111143 25-Nov-14 1:35am    
Please Someone help me in for this query....
mudgilsks 5-Dec-14 5:41am    
Dim grvStudentDetails As GridView = DirectCast(FindControl("grvStudentDetails"), GridView)





Dim dtCostCenterviewState As New DataTable()
Dim drCostCenter As DataRow = Nothing


dtCostCenterviewState.Columns.Add(New DataColumn("RowNumber", GetType(String)))

dtCostCenterviewState.Columns.Add(New DataColumn("gl_id", GetType(String)))

dtCostCenterviewState.Columns.Add(New DataColumn("cost_center_desc", GetType(String)))


Dim drCurrentRow As DataRow = Nothing
Dim drCostCenterCurrentRow As DataRow = Nothing
'If dtCurrentTable.Rows.Count > 0 Then
Dim i As Integer = 1


Dim grdCostcenter As GridView = DirectCast(FindControl("grdCostcenter"), GridView)

'Dim j As Integer = 1

For Each rowCostCenter As GridViewRow In grdCostcenter.Rows


Dim cost_center_desc As Label = DirectCast(rowCostCenter.FindControl("cost_center_desc"), Label)




drCostCenterCurrentRow = dtCostCenterviewState.NewRow()


drCostCenterCurrentRow("RowNumber") = 1
drCostCenterCurrentRow("gl_id") = 1
drCostCenterCurrentRow("cost_centre_id") = cost_center_desc.Text


'j = j + 1

dtCostCenterviewState.Rows.Add(drCostCenterCurrentRow)
Next

'' ViewState("CurrentCostCenterTable") = dtCostCenterviewState

Session["GridData"] =dtCostCenterviewState '' ViewState("CurrentCostCenterTable")

Response.Redirect("ReciveChallan.aspx");
dim dt as datatable= Session["GridData"]

Try this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900