zoukankan      html  css  js  c++  java
  • [转载]LinkButton跳转页面及传递参数

    在DataList中使用LinkButton按钮(LinkButtonDelete),该按钮用于链接跳转到删除页面。在模板中双击该按钮,跳转到.cs页面。问题是我们如何获得该条信息的ID,如果不知道ID值,我们又怎么知道需要删除的是哪一条信息呢?通过下面的方法就可以了:

    在LinkButtonDelete控件中加入属性CommandArgument和CausesValidation,如下:
    <asp:LinkButton ID="LinkButtonDelete"  CommandArgument='<%# Eval("infoId")%>' CausesValidation="false" runat="server" OnClick="LinkButtonDelete_Click">删除</asp:LinkButton>
    infoId就是在数据库中定义的ID字段。


    在cs文件中获取该ID值,代码如下:
      protected void btndelete_Click(object sender,EventArgs e)
            {
                string deleteId=(((LinkButton)sender).CommandArgument.ToString()).ToString();
                if (deleteId != "")
                {
                    string sql = "delete from gsinfotable where infoId=" + int.Parse(deleteId);
                    DBHelper.ExecNonQuery(sql);
                    Response.Redirect("Index.aspx");
                }
            }

  • 相关阅读:
    Python 文件操作
    Python 操作 sqlite
    Python中的random模块
    Linux系统下的/etc/nsswitch.conf文件
    Python 列表/元组/字典总结
    快斗之翼:python2的print和python3的print()
    田小计划:图解Python深拷贝和浅拷贝
    Python 自省指南
    Python运算符优先级
    tc: 模拟网络异常的工具
  • 原文地址:https://www.cnblogs.com/AaronBear/p/5985692.html
Copyright © 2011-2022 走看看