问题描述
我已经关注过的大家好
我在行绑定方法的网格中动态添加按钮
代码如下
受保护的void gvwPlanDetail_RowDataBound(object sender,GridViewRowEventArgs e)
{
如果(e.Row.RowType == DataControlRowType.DataRow)
{
字符串状态= e.Row.Cells [4] .Text;
如果(status.ToLower()=="ACCEPTED" .ToLower())
{
ImageButton btnCancel = new ImageButton();
btnCancel.ImageUrl =".. \\ images \\ Cancel_New.gif";
btnCancel.ToolTip =取消方案";
btnCancel.Click + = new ImageClickEventHandler(btnCancel_Click);
e.Row.Cells [4] .Controls.Add(btnCancel);
}
}
}
我在这里添加btnCancel_点击此方法
此方法中的代码是
受保护的无效btnCancel_Click(对象发送者,ImageClickEventArgs e)
{
GridViewRow gridViewRow =(GridViewRow)(发送方为控件).Parent.Parent;
int索引= gridViewRow.RowIndex;
objClients.ClientCode = gvwPlanDetail.Rows [index] .Cells [0] .Text;
objClients.SchemeName = gvwPlanDetail.Rows [index] .Cells [1] .Text;
objClientBase.CancelPlan(objClients);
BindGvwPlanDetail();
}
但是当我单击取消"按钮时,它无法导航到该方法
请告诉我
在这一点上我错了.
谢谢你
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
推荐答案
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();
}
这篇关于来自btnclick的方法未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!