page_load里如何取得linkbutton的CommandArgument值??????

jlqidan 2003-09-14 11:51:31
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
LinkButton1.CommandArgument = "LinkButton1";
LinkButton1.CommandArgument = "LinkButton2";
}
page_load函数中如下:
string arg = ((LinkButton)sender).CommandName;
报错是:
指定的转换无效!!!!!!!!!!!!!!

我不想指定linkbutton的click事件处理函数,只想再page_load里面知道那个linkbutton被click了就可以了.
...全文
100 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2003-09-15
  • 打赏
  • 举报
回复
in Page_Load, sender is the Page object itself!!

>>>只想再page_load里面知道那个linkbutton被click了就可以了.

use Request.Form["__EVENTTARGET"]
jlqidan 2003-09-14
  • 打赏
  • 举报
回复
string arg = ((LinkButton)sender).CommandArgument
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { getData(); } } //得到数据 public void getData() { this.GridView1.DataSource = BLL.mesManager.getGridData(); this.GridView1.DataBind(); } // 绑定之后发生 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton lbtn = (LinkButton)e.Row.FindControl("LinkButton2"); e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor"); string aa = e.Row.Cells[3].Text.ToString(); lbtn.Attributes.Add("OnClick", "return confirm('您确认要删除吗?')"); } } //发生时间时激发 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "del") { int id = Convert.ToInt32(e.CommandArgument); int resultNum = BLL.mesManager.del(id); if (resultNum > 0) { Response.Write("<script>alert('删除成功');CommandName == "upd") { int id = Convert.ToInt32(e.CommandArgument); Response.Redirect("Update.aspx?id=" + id); } } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { } //pageindexchangeing protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { this.GridView1.PageIndex = e.NewPageIndex; getData(); } //全部删除 protected void Button1_Click(object sender, EventArgs e) { for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); if (cbox.Checked == true) { int id=Convert.ToInt32( this.GridView1.Rows[i].Cells[1].Text); BLL.mesManager.del(id); } } getData(); } }

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧