Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i created a dataTable and Bind it in DataGrid in ASP.net so i want to Remove first row for example by Clicking Delete Event ...


C#
protected void btnAddName_Click(object sender, EventArgs e)
{       
        DataTable dt;
        if (Session["dt"] == null)
        {
            dt = new DataTable();
            dt.Columns.Add(new DataColumn("lblName", typeof(string)));
        }
        else
        {
            dt = (DataTable)Session["dt"];
        }

        DataRow _dr = dt.NewRow();
        _dr["lblName"] = txtName.Text;
        dt.Rows.Add(_dr);

        gvName.DataSource = dt;
        //dt.Rows.Remove[dt[0]];
        gvName.DataBind();

        Session["dt"] = dt; 
    }

C#
protected void gvName_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "Delete")
       {
           int ReferralId = Convert.ToInt32(e.CommandArgument);
           // Delete the record
          Response.Write(ReferralId);


// Where should i Remove ReferralId from DataTable ????????


       }
   }
Posted
Updated 13-Mar-13 2:18am
v2
Comments
Jameel VM 13-Mar-13 11:08am    
did u want to delete records from database too?

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