Click here to Skip to main content
15,921,210 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Dear Friends,

I have a GRIDVIEW on my webpage and displayed data in it from database its working fine.

I have a Command Field in it with Select Button = TRUE.

XML
<Columns>

<asp:CommandField ShowSelectButton="True"/>

  </Columns>


code Page
=========
C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ClearanceNumber");
        dt.Columns.Add("CodeTrainId");
        dt.Columns.Add("DateLastChange");
        dt.Columns.Add("DateValidFrom");
        dt.Columns.Add("DateValidTo");
        dt.Columns.Add("ReservationNo");
        dt.Columns.Add("TrainType");
        dt.Columns.Add("CityCode");
        dt.Columns.Add("Days");

        DataRow dataRow;
        dataRow = dt.NewRow();

        for (int i = 0; i < dataRow.Table.Columns.Count; i++)
        {
            dataRow[i] = GridView1.SelectedRow.Cells[i + 1].Text;
            GridView1.Rows[0].Cells[0].BackColor = System.Drawing.Color.Blue;
        }

        dt.Rows.Add(dataRow);
        Session["dataTable"] = dt;

        Response.Redirect("Selected.aspx");
}


Suppose, If i click this Select button in Gridview, it Redirects to another page. and Displays only Selected Record and when Print button clicks it is printing all the gridview Records. SO I DONT WANT THIS.



MY REQUIREMENT IS : :


When i Click the Select Button in Gridview, that particular row must INSERT into Another Table in Sqlserver 2005 Database. for this i have Created a New table to Insert this Row.

This New Table I Will Use for Crystal Reports for Printing that Particular Record.


Please help me,

Thanks in ADVANCE.
Posted
Updated 19-Jun-12 21:04pm
v2

1 solution

can u able to post ur full code....
 
Share this answer
 

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