Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I dynamically created button in GridView, after the button click you want the button to be removed dynamically, but my problem seems that I could not find the control in the GrideViw.
Below is some of my codes:

1.GridView Rowdatabond that created the button

public void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

PlaceHolder ph = (PlaceHolder)e.Row.FindControl("ph1");
Button bt1 = new Button();

bt1.ID = "GameCall" ;

bt1.Text = "Game Call";

bt1.CommandName = "GameCall";

bt1.EnableViewState = true;

ph.Controls.Clear();

ph.Controls.Add(bt1);



}

2.The GridView RowCommand that execute the click event
public void GridViewUserLots_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "GameCall")
{



Button bt1 = (Button)e.CommandSource;
GridViewRow row = (GridViewRow)bt1.NamingContainer;
PlaceHolder ph = (PlaceHolder)row.FindControl("ph1");

TextBox PlayerID = (TextBox)row.FindControl("PlayerId");
string PlayerId = PlayerID.Text;

if (bt1 != null)
{
the event happened here
}

ph1.Controls.Remove(bt1);

What I have tried:

I tried to use the following code to remove the button bt1

ph1.Controls.Remove(bt1);

but the button still remain.
Posted
Updated 6-Nov-16 13:31pm

1 solution

Have you tried calling ph1.UpdateLayout(); after removing?
 
Share this answer
 

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