• 通过SelectedIndexChanged获取当前行


    XHTML结构:

    <asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false" DataKeyNames="MATNR"
        CellSpacing="0" CellPadding="0" BorderWidth="0" GridLines="None"
        OnSelectedIndexChanged="gvList_SelectedIndexChanged" >
        <Columns>
            <asp:TemplateField HeaderText="操作">
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="lbtnShoppingCart" Text="+加入购物车" OnCommand="lbtn_Command"
                        CommandName="Select" CommandArgument="ShoppingCart">
                    </asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    .cs(C#):

    private string CmdArg = string.Empty;
    
    protected void lbtn_Command(object o, CommandEventArgs e)
    {
        CmdArg = e.CommandArgument.ToString();
    }
    
    protected void gvList_SelectedIndexChanged(object o, EventArgs e)
    {
        GridView gv = (GridView)o;
        GridViewRow row = gv.Rows[gv.SelectedIndex];
        switch (CmdArg)
        {
            case "ShoppingCart":
                string _Material = gvList.DataKeys[gvList.SelectedIndex].Value.ToString();
               
                //code here ...
    
                }//end of if
                break;
        }//end of switch
    }
    
  • 相关阅读:
    后缀数组模板~~~
    CF 196 Div2 D&&HDU 4679 && HDU 2196
    .......
    ~~~~~
    主站点~~~~
    C++抽象,封装,继承,多态
    查缺补漏知识点(二)
    Qt的简介
    C语言指针及C++引用
    C++单例模式
  • 原文地址:https://www.cnblogs.com/cancer_xu/p/2186224.html
Copyright © 2020-2023  润新知