Last post Aug 31, 2016 06:30 AM by Cathy Zou
Aug 30, 2016 01:03 PM|sengson|LINK
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.Visible = false;
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 < GVdata.Rows.Count; i++)
// ADD LINK BUTTON IF row.text != Empty(Blank)
if (e.Row.Cells[i + 3].ToString() != "&nbsp;")
if (e.Row.Cells[i + 3].ToString() != " ")
if (e.Row.Cells[i + 3].ToString() != string.Empty)
Label txt = new Label();
LinkButton lb1 = new LinkButton();
lb1.ID = k + "_" + (i + 3) + "Btn1";
lb1.Text = " Update ";
lb1.ForeColor = System.Drawing.Color.Blue;
LinkButton lb2 = new LinkButton();
lb2.ID = k + "_" + (i + 3) + "Btn2";
lb2.Text = " Delete ";
lb2.ForeColor = System.Drawing.Color.Red;
lb1.CausesValidation = false;
lb1.Click += new EventHandler(Update_Click);
lb2.CausesValidation = false;
lb2.Click += new EventHandler(Delete_Click);
txt.Text = GridViewTable.Rows[index][i + 3].ToString();
e.Row.Cells[i + 3].Controls.Add(txt);
e.Row.Cells[i + 3].Controls.Add(lb1);
e.Row.Cells[i + 3].Controls.Add(lb2);
Aug 31, 2016 06:30 AM|Cathy Zou|LINK
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.