红色是错误 处,应该怎么改正?急急。。
protected void GVdetail_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "AddToBus")
        {
            string petID = this.GVdetail.DataKeys[e.Row.RowIndex].ToString();         
           if (Session["bus"] == null)
            {
                System.Collections.Hashtable ht = new Hashtable();                ht.Add(petID, 1);
                Session["bus"] = ht;
               // Session.Add("bus", ht);
            }
            else 
            {System.Collections .Hashtable ht=(Hashtable )Session ["bus"];
            if (ht[petID] == null)
            {
                ht[petID] = 1;
            }            else
            {
                ht[petID] = (int)ht[petID] + 1;
            }            Session["bus"] = ht;
            }
        }    }
错误 1 “System.Web.UI.WebControls.GridViewCommandEventArgs”并不包含“Row”的定义

解决方案 »

  1.   

    试试: Button btn = (Button)sender;
            GridViewRow gvr = (GridViewRow)btn.Parent.Parent;
            string pk = GVdetail.DataKeys[gvr.RowIndex].Value.ToString();
      

  2.   


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    int rowIndex = int.Parse(e.CommandArgument.ToString());
    }
      

  3.   


    <asp:TemplateField ShowHeader="False">
         <ItemTemplate>
            <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="Fuck" Text="Test" CommandArgument='<%# Container.DisplayIndex %>' />
         </ItemTemplate>
    </asp:TemplateField>protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
            if (e.CommandName == "Fuck")
            {
                Response.Write(string.Format("{0}", GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value));
            }
    }
      

  4.   

    string petID = this.GVdetail.DataKeys[e.Row.RowIndex].ToString();   
    少了个.value()!!!!        
      

  5.   

     protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "aaa")
            {
                string id = GridView1.DataKeys[e.CommandArgument].ToString();
            }    }你的那个控件里面的必须绑定你要得到的id;<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" Text="Button" CommandName="aaa" CommandArgument='<%#Eval("Id") %>' />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        </asp:GridView>   
      

  6.   

    综合 了一下,成功了!string petID = this.GVdetail.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString ();
      

  7.   

     把红的那点换成下面的代码
    int index=Convert.ToInt32(e.CommandArgument);
    DataKey key=this.GridView1.DataKeys[index];
    string petID =key.value.ToString();