How to add and update a datagridview(code inside) ?

Discussion in 'C#' started by sxcnelson, Feb 20, 2010.

  1. #1
    sxcnelson, Feb 20, 2010 IP
  2. sauravmandhotra

    sauravmandhotra Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    usinf edititem template of datagrid to update
     
    sauravmandhotra, Jul 31, 2010 IP
  3. susasl

    susasl Active Member

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    Here is the sample code for updating..
    protected void grvVideos_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    try
    {
    GridViewRow row = grvVideos.Rows[e.RowIndex];
    if (row != null)
    {
    Label lblID = (Label)row.FindControl("lblID");
    TextBox txtTitle = (TextBox)row.FindControl("txtNewTitle");
    TextBox txtSubTitle = (TextBox)row.FindControl("txtNewSubTitle");
    TextBox txtDescription = (TextBox)row.FindControl("txtNewDescription");
    TextBox txtFileName = (TextBox)row.FindControl("txtNewFileName");
    TextBox txtLink1 = (TextBox)row.FindControl("txtNewLink1");
    TextBox txtLink2 = (TextBox)row.FindControl("txtNewLink2");
    int id = int.Parse(lblID.Text.Trim());

    string title = txtTitle.Text.Trim().Replace("'", "''");
    string subtitle = txtSubTitle.Text.Trim().Replace("'", "''");
    string description = txtDescription.Text.Trim().Replace("'","''");
    string filename = txtFileName.Text.Trim();
    string link1 = txtLink1.Text.Trim();
    string link2 = txtLink2.Text.Trim();

    Videos oVideos = new Videos();

    bool VideoChanged = oVideos.UpdateVideos(id, title, subtitle, description, filename, link1, link2);
    if (VideoChanged == true)
    {
    grvVideos.EditIndex = -1;
    GetData();

    }
    }
    }
     
    susasl, Jul 31, 2010 IP
  4. sauravmandhotra

    sauravmandhotra Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    TextBox txtTitle = ((TextBox)row.FindControl("txtNewTitle")).text;
     
    sauravmandhotra, Jul 31, 2010 IP