Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys i have following

I am Adding Dynamically Button in grid on rowbound method
code is as follow
protected void gvwPlanDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string status = e.Row.Cells[4].Text;
if (status.ToLower() == "ACCEPTED".ToLower())
{
ImageButton btnCancel = new ImageButton();
btnCancel.ImageUrl = "..\\images\\Cancel_New.gif";
btnCancel.ToolTip = "Cancel Scheme";
btnCancel.Click +=new ImageClickEventHandler(btnCancel_Click);
e.Row.Cells[4].Controls.Add(btnCancel);
}
}
}


here i am addinng btnCancel_Click this method
code in this method are
protected void btnCancel_Click(object sender, ImageClickEventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
objClients.ClientCode = gvwPlanDetail.Rows[index].Cells[0].Text;
objClients.SchemeName = gvwPlanDetail.Rows[index].Cells[1].Text;
objClientBase.CancelPlan(objClients);
BindGvwPlanDetail();

}


but when i click on cancel button it can not navigate to the that method
please tell me
at which point i m wrong.

thank u
Posted
Comments
anushripatil 28-Dec-11 0:06am    
u can try
btnCancel.Attributes.Add("onlclick", "ur method")
U can check out this post
http://www.codeproject.com/Questions/287725/generating-the-event-handlers-for-dynamically-crea
or
http://bytes.com/topic/asp-net/answers/593117-event-handlers-dynamically-created-controls

C#
protected void gvwPlanDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string status = e.Row.Cells[4].Text;
if (status.ToLower() == "ACCEPTED".ToLower())
{
ImageButton btnCancel = new ImageButton();
btncancel.id="img1"
btnCancel.ImageUrl = "..\\images\\Cancel_New.gif";
btnCancel.ToolTip = "Cancel Scheme";
btnCancel.Click +=new ImageClickEventHandler(btnCancel_Click);
e.Row.Cells[4].Controls.Add(img1);
}
}
}
 

here i am addinng btnCancel_Click this method
code in this method are 
protected void btnCancel_Click(object sender, ImageClickEventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
objClients.ClientCode = gvwPlanDetail.Rows[index].Cells[0].Text;
objClients.SchemeName = gvwPlanDetail.Rows[index].Cells[1].Text;
objClientBase.CancelPlan(objClients);
BindGvwPlanDetail();
 
}
 
Share this answer
 
The best overloaded method match for 'System.Web.UI.ControlCollection.Add(System.Web.UI.Control)' has some invalid arguments

it will
show this error


plz mention where u are changing the code
 
Share this answer
 
the control should be loaded each time on page load.
therefore remove the ispost from page load.
solution of above.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900