locked
how to delete single cell of gridview at a time when click on related cell button RRS feed

  • Question

  • User-1235203782 posted


    How can I find the column index dynamically of selected Linkbutton when click on any of the link button which is created dynamically. All the buttons are created dynamically and also rows and columns are created dynamically in gridview. I need to Delete
    Individual Cell of gridview when click on related Linkbutton.. So that I need to find column and Row Index.This screen shot gives an idea of the problem.
    This Code is for creating Link button Dynamically where Columns are not fixed. and I Need to delete single cell when click on delete button of related Cell of gridview.
    <pre class="prettyprint">protected void gv_TT_RowCreated(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.Header)
    {
    e.Row.Cells[2].Visible = false;
    e.Row.Cells[1].Attributes.Add(colspan);
    }
    int index = e.Row.RowIndex;
    int k = 0;
    GVdata = (DataTable)ViewState[GVdata];
    GridViewTable = (DataTable)ViewState[GridViewTable];

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    for (int i = 0; i &lt; GVdata.Rows.Count; i&#43;&#43;)
    {

    // ADD LINK BUTTON IF row.text != Empty(Blank)
    if (e.Row.Cells[i &#43; 3].ToString() != &quot;&amp;nbsp;&quot;)
    {
    if (e.Row.Cells[i &#43; 3].ToString() != &quot; &quot;)
    {
    if (e.Row.Cells[i &#43; 3].ToString() != string.Empty)
    {
    Label txt = new Label();

    LinkButton lb1 = new LinkButton();
    lb1.ID = k &#43; &quot;_&quot; &#43; (i &#43; 3) &#43; &quot;Btn1&quot;;
    lb1.Text = &quot; Update &quot;;
    lb1.ForeColor = System.Drawing.Color.Blue;

    LinkButton lb2 = new LinkButton();
    lb2.ID = k &#43; &quot;_&quot; &#43; (i &#43; 3) &#43; &quot;Btn2&quot;;
    lb2.Text = &quot; Delete &quot;;
    lb2.ForeColor = System.Drawing.Color.Red;

    lb1.CausesValidation = false;
    lb1.Click &#43;= new EventHandler(Update_Click);
    lb2.CausesValidation = false;
    lb2.Click &#43;= new EventHandler(Delete_Click);

    txt.Text = GridViewTable.Rows[index][i &#43; 3].ToString();
    e.Row.Cells[i &#43; 3].Controls.Add(txt);
    e.Row.Cells[i &#43; 3].Controls.Add(lb1);
    e.Row.Cells[i &#43; 3].Controls.Add(lb2);
    }
    }
    }
    }

    ssfff

    Tuesday, August 30, 2016 1:03 PM

All replies

  • User-707554951 posted

    Hi sengson,

    sengson

    How can I find the column index dynamically of selected Linkbutton when click on any of the link button which is created dynamically.

    For the question above, I suggest you could find the cell in which selected link button located in by using link button’s parent property, the you could set it’s visible to false to hide the cell.
    If you didn’t want to hide cell, would you please provide full code about the problem and display us with the result structure after you delete cell. i.e, you want do what change for the cell around the selected cell you want to delete.
    Best regards
    Cathy

    Wednesday, August 31, 2016 6:30 AM