首页 > 其他分享 >CommandArgument用法

CommandArgument用法

时间:2022-11-10 10:45:07浏览次数:36  
标签:CommandArgument string tag CommandName 用法 num 主键

https://www.cnblogs.com/lyy445910200/p/5420554.html

1.绑定数据库中一个主键
前台代码:
<ItemTemplate>
                        <asp:ImageButton ID="ibtnUpdate" runat="server" CommandArgument='<%# Eval("studentNum")%>'
                            CommandName="edit" />
                    </ItemTemplate>
就可以通过GridView的RowCommand事件获得此行的主键,进而获得此行数据。
protected void gvSelectTask_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string temp = e.CommandArgument.ToString().Trim();
            //string[] num = temp.Split(',');
            string tag = e.CommandName.ToString().Trim();
            //if (tag == "edit")
            //{
            //    CreativeStudio.Common.alert.GoHref("selectTaskEdit.aspx?studentN="+ num[0] +"&teacherN="+num[1]+"");
           // }
           // else if (tag == "delete") //删除选课记录的时候没有必要删除学生记录
           // {
            //    sTaskBLL.Delete(num[0]);
               // Bind();
           // }
        }


2.如果涉及到主键是两个字段或者要同时绑定两张表的主键那么用法为
前台代码:
<ItemTemplate>
                        <asp:ImageButton ID="ibtnUpdate" runat="server" CommandArgument='<%# Eval("studentNum")+","+Eval("teacherNum")%>'
                            CommandName="edit" />
                    </ItemTemplate>
同样可以获得表中一行数据,或者同时获得两张表的各一行数据。
protected void gvSelectTask_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string temp = e.CommandArgument.ToString().Trim();
            string[] num = temp.Split(',');
            string tag = e.CommandName.ToString().Trim();
            //if (tag == "edit")
            //{
            //    CreativeStudio.Common.alert.GoHref("selectTaskEdit.aspx?studentN="+ num[0] +"&teacherN="+num[1]+"");
           // }
           // else if (tag == "delete") //删除选课记录的时候没有必要删除学生记录
           // {
            //    sTaskBLL.Delete(num[0]);
               // Bind();
           // }
        }

标签:CommandArgument,string,tag,CommandName,用法,num,主键
From: https://www.cnblogs.com/Dongmy/p/16876298.html

相关文章

  • c语言中位运算符及用法 异或
    a&b: 0000000000000000  a&b=0x0a|b:0000000001011111  a|b=0x5fa^b:0000000001011111  a^b=0x5f~a :1111111111110000   ~a=0xfff0转载:https:......
  • C++中virtual(虚函数)的用法
    C++中virtual(虚函数)的用法在面向对象的C++语言中,虚函数(virtual function)是一个非常重要的概念。什么是虚函数:虚函数是指一个类中你希望重载的成员函数,当你用一个......
  • tmux 基本用法
    新建会话:tmuxnew-s<name>列出会话:tmuxls切换会话:tmuxa-t<session-name>从tmux会话中返回控制台C-bd在tmux会话中创建窗口C-bc在tmux会话中......
  • Linux操作系统之chmod命令详细用法:Linux中的Chmod命令用于更改或分配文件和目录的权限
    前言①chmod命令用于改变Linux操作系统文件或目录的访问权限。用它控制文件或目录的访问权限。②chmod命令有两种用法一种是包含字母和操作符表达式的文字设定法。一......
  • Redux 概念和基本用法
    前言本文主要以Rudex结合Racte的方式,对Redux的基本概念和用法进行记录;Rudex是什么Rudex是一个以集中式Store的方式对整个应用中使用的状态进行集中管理,确保状......
  • react进阶用法完全指南
    React调用回调函数,正确设置this指向的三种方法通过bindthis.increment=this.increment.bind(this);通过箭头函数<buttononClick={this.multi}>点我*10</button......
  • Yii2的ListView用法
    Yii2的ListView用法控制器publicfunctionactionListView(){$this->layout=false;$dataProvider=newActiveDataProvider(['......
  • Yii2 DetailView用法
    Yii2DetailView用法控制器代码publicfunctionactionDetailView(){//获取一条记录$model=Resource::find()->with(['resourceType'])->where(['......
  • pip 用法一览表
    使用pip安装模块:使用命令:pipinstallPackageName使用pip更新模块:使用命令:pipinstall-UPackageName使用pip卸载模块:使用命令:pipuninstallPackageName......
  • JavaScript中foreach()用法及使用的坑
    JavaScript中foreach是用于遍历数组的方法,将遍历到的元素传递给回调函数,遍历的数组不能是空的要有值。foreach语法:[].forEach(function(value,index,array){//codeso......