• CommandArgument用法


    CommandArgument用法

     
    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();
               // }
            }
    http://www.cnblogs.com/forever4444/archive/2009/07/19/1526638.html
    原文网址,写的不错
  • 相关阅读:
    hdu 5723 Abandoned country 最小生成树 期望
    OpenJ_POJ C16G Challenge Your Template 迪杰斯特拉
    OpenJ_POJ C16D Extracurricular Sports 打表找规律
    OpenJ_POJ C16B Robot Game 打表找规律
    CCCC 成都信息工程大学游记
    UVALive 6893 The Big Painting hash
    UVALive 6889 City Park 并查集
    UVALive 6888 Ricochet Robots bfs
    UVALive 6886 Golf Bot FFT
    UVALive 6885 Flowery Trails 最短路
  • 原文地址:https://www.cnblogs.com/lyy445910200/p/5420554.html
Copyright © 2020-2023  润新知