如何调用code按钮的onclick事件处理程序用一个值后面? [英] How to call Button OnCLick eventhandler in code behind with a value?

查看:117
本文介绍了如何调用code按钮的onclick事件处理程序用一个值后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创造的背后code锚和删除按钮以及每个锚。我不知道如果我可以调用的链接中的每一个的事件处理程序的ID,所以我可以从数据库中删除指定的行。这是我做了什么。我创建了一个锚的ASP按钮,但不知道我怎么能与ImageID调用它。可能吗?如果是这样如何?非常感谢事先!这是在C#中,asp.net。

 的HtmlAnchor APDF =新的HtmlAnchor();
 。apdf.ID = Guid.NewGuid()的ToString(N);
 字符串ImageID =;
 如果(dsreport =空&放大器;!&放大器; dsreport.Tables [0] .Rows.Count大于0)
 {
      。apdf.InnerText = dsreport.Tables [0] .Rows [0] [ImageName]的ToString();
      apdf.Attributes.Add(风格,字体重量:大胆; FONT-SIZE:13px的;保证金:0像素; FONT-FAMILY:宋体;颜色:#1e7c9b;文本修饰:下划线);
      apdf.Target =_blank;
      。ImageSalesID = dsreport.Tables [0] .Rows [0] [ImageID]的ToString();
      apdf.HRef =?PDFdownload.aspx ID =+ ImageID; }
 按钮btnDelete =新按钮();
 。btnDelete.ID = Guid.NewGuid()的ToString(N);
 btnDelete.OnClick + =事件处理程序;
 btnDelete.Text =删除;


解决方案

我希望这可以帮助你以某种方式

 按钮btnDelete =新按钮();
    btnDelete.Click + =新的EventHandler(button_Click);    保护无效button_Click(对象发件人,EventArgs的发送)
    {
        Button按钮=发送者的按钮;
        字符串buttonid = button.ID.ToString()
        //确定哪个按钮是更新基于ID哪一行点击并执行必要的行动
    }

I am trying to create Anchors in code behind and delete buttons as well for each Anchor. I dont know if i can call an event handler for each one of the link with an ID so i can delete the row specified from the database. This is what i have done. I created an anchor and an ASp button but not sure how i can call it with that ImageID. Is it possible? If so How? Thanks a lot in advance!! This is in C#, asp.net.

 HtmlAnchor apdf = new HtmlAnchor();
 apdf.ID = Guid.NewGuid().ToString("N");
 string ImageID = "";
 if (dsreport != null && dsreport.Tables[0].Rows.Count > 0)
 {
      apdf.InnerText = dsreport.Tables[0].Rows[0]["ImageName"].ToString();
      apdf.Attributes.Add("style", "font-weight: bold; font-size: 13px; margin: 0px;    font-family: Arial; color: #1e7c9b; text-decoration: underline");
      apdf.Target = "_blank";
      ImageSalesID = dsreport.Tables[0].Rows[0]["ImageID"].ToString();
      apdf.HRef = "PDFdownload.aspx?ID=" + ImageID;

 }   
 Button btnDelete = new Button();
 btnDelete.ID = Guid.NewGuid().ToString("N");
 btnDelete.OnClick += Eventhandler;
 btnDelete.Text = "Delete";

解决方案

I hope this may help you in some way

 Button btnDelete = new Button();
    btnDelete.Click += new EventHandler(button_Click);

    protected void button_Click (object sender, EventArgs e)
    {
        Button button = sender as Button;
        string buttonid = button.ID.ToString()
        // identify which button was what row to update based on id clicked and perform necessary actions
    }

这篇关于如何调用code按钮的onclick事件处理程序用一个值后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆