在gridview中的linkbutton事件,无法触发~~~~~~~
GridView1_RowDataBound1在这里写LinkButton glbt = new LinkButton();
glbt.Text = e.Row.Cells[1].Text;
e.Row.Cells[1].Controls.AddAt(0, glbt);
glbt.CommandName = "gridlist";
然后在
GridView1_RowCommand里面写
if (e.CommandName == "gridlist")
{
操作~~~~~~~
}
protected void glbt_Click(object sender, EventArgs e)
{
操作~~~~~
}
为什么点linkbutton没有任何响应。 --------------------编程问答-------------------- protected void myGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
string id;
id = myGridView.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].Text;
switch (e.CommandName)
{
case "Delete":
whb147.BLL.USER_LEVEL bll = new whb147.BLL.USER_LEVEL();
bll.Delete(int.Parse(id));
break;
case "Edit":
Response.Redirect("User_Info_Edit.aspx?ID=" + id);
break;
case "View":
Response.Redirect("User_Info_View.aspx?ID=" + id);
break;
default:
break;
}
} --------------------编程问答-------------------- TO:whb147(苦乐随缘) 您的方法不行~~~~~
--------------------编程问答-------------------- 他的方法和你自己的一样的
--------------------编程问答-------------------- 在GridView1_RowDataBound事件写
LinkButton linkBtn= e.Row.FindControl("LinkButton1") as LinkButton;
if (linkBtn != null)
{
linkBtn.CommandName = "TT";
}
在GridView1_RowCommand事件写
if (e.CommandName == "TT")
{
//执行操作
Response.Write("Yes");
}
~~~~~~~~~~~接分~~~~~~~~~~~~~~~~
--------------------编程问答-------------------- TO:liusen5555() ,您的方法跟我的一样
如果是模板列那这样写是可以的,但是我是手动添加linkbutton控件
--------------------编程问答-------------------- GridView1_RowDataBound1在这里写
LinkButton glbt = new LinkButton();
glbt.Text = e.Row.Cells[1].Text;
e.Row.Cells[1].Controls.AddAt(0, glbt);
glbt.CommandName = "gridlist";
在RowCreated中写试试
--------------------编程问答-------------------- 动态添加的控件在点击的时候状态就丢失了..
如果想保存状态..需要每次在pageLoad事件里都加载你的那个控件才行的... --------------------编程问答-------------------- 既然你每行都要LinkButton,为何不直接先拖控件出来呢,只要给赋值Text就好了啊 --------------------编程问答-------------------- 试试在RowCreated中把LinkButton创建出来,并指定CommandName
然后在RowDataBound给LinkButton的TEXT赋值 --------------------编程问答-------------------- protected void gvwContract_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
int objid = Convert.ToInt32(gvwContract.DataKeys[index].Value);
string url;
url = "ContractDocs.aspx?objectid=" + objid;
Response.Redirect(url);
//Response .Redirect ("ContractDocs.aspx?objectid="+objid )
}
protected void gvwContract_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton LinkButton1 = (LinkButton)e.Row.FindControl("LinkButton1");
LinkButton1.CommandArgument = e.Row.RowIndex.ToString();
}
} --------------------编程问答-------------------- 检查linkbutton的click事件名称是否和你写的事件名称一致 --------------------编程问答-------------------- 要么用模板列,要么加上委托!!!
补充:.NET技术 , ASP.NET