Copying data from Gridview

Discussion in 'ASP.NET' started by Jymoz, Aug 19, 2011.

  1. Jymoz

    Jymoz New Member

    Joined:
    Aug 17, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I have an ASP.NET page with a C# code behind and i'm working a lot with gridviews to display data.

    I have one that displays tasks for the current date and with checkboxes that allows the user to select multiple rows. I'm looking into a way that would allow the users to select tasks in the gridview, select a date from a drop down and press a button to copy all the data from the rows and insert it back into the database but with the date selected.

    I know that it'll be a simple insert statement triggered by the button. But i dont know how to get the data from the rows selected in the grid view and put them in the new insert statement. Can anyone help?
     
  2. alia123

    alia123 New Member

    Joined:
    Jan 8, 2016
    Messages:
    65
    Likes Received:
    5
    Trophy Points:
    0
  3. Ami Desai

    Ami Desai Member

    Joined:
    Jan 5, 2017
    Messages:
    42
    Likes Received:
    17
    Trophy Points:
    8
    Location:
    Ahmedabad
    Home Page:
    http://www.ifourtechnolab.com/
    Hi,

    You can check this

    Code:
    protected void OnSelectedIndexChanged(object sender, EventArgs e)
    {
        //Accessing BoundField Column
        string name = GridView1.SelectedRow.Cells[0].Text;
        //Accessing TemplateField Column controls
        string country = (GridView1.SelectedRow.FindControl("lblCountry") as Label).Text;
        lblValues.Text = "<b>Name:</b> " + name + " <b>Country:</b> " + country;
    }
    Thanks
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice