红色是错误 处,应该怎么改正?急急。。
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”的定义
GridViewRow gvr = (GridViewRow)btn.Parent.Parent;
string pk = GVdetail.DataKeys[gvr.RowIndex].Value.ToString();
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = int.Parse(e.CommandArgument.ToString());
}
<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));
}
}
少了个.value()!!!!
{
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>
int index=Convert.ToInt32(e.CommandArgument);
DataKey key=this.GridView1.DataKeys[index];
string petID =key.value.ToString();