protected void gvCarLendInfo_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Response.Redirect(string.Format("CarLendManage.aspx?ItemBH={0}", gvCarLendInfo.DataKeys[Convert.ToInt32(e.CommandArgument)]));
        }gvCarLendInfo的DataKeys属性也是设置的了!!!

解决方案 »

  1.   

    DataKeys未获取到值,没绑定上。
      

  2.   

    gvCarLendInfo.DataKeys[Convert.ToInt32(e.CommandArgument)
    这种写法不对一般是直接e.CommandArgument
      

  3.   

    我对gvCarLendInfo添加监控
    在监控里看到这几个数据,大家看下是不是DataKeys拍[]的问题~
    DataKeyNames {维数:[1]} string[]
    [0] "BH" string- DataKeys {System.Web.UI.WebControls.DataKeyArray} System.Web.UI.WebControls.DataKeyArray
    Count 0 int
    IsReadOnly false bool
    IsSynchronized false bool
    + SyncRoot {System.Web.UI.WebControls.DataKeyArray} object {System.Web.UI.WebControls.DataKeyArray}
      

  4.   

    <asp:GridView id="gvCarLendInfo" runat="server" Width="90%" OnPreRender="gvCarLendInfo_PreRender" CellSpacing="1" CaptionAlign="Bottom" BorderColor="Black" OnRowCommand="gvCarLendInfo_RowCommand" AutoGenerateColumns="False" DataKeyNames="BH" AllowPaging="True" AllowSorting="True">
            <Columns>
                <asp:ButtonField Text="编辑" ButtonType="Button">
                    <HeaderStyle BackColor="#0000C0" Font-Size="Smaller"  />
                    <ItemStyle HorizontalAlign="Center" Wrap="False"  />
                </asp:ButtonField>
                <asp:BoundField DataField="BH" HeaderText="编号">
                    <FooterStyle BackColor="#80FFFF" />
                    <HeaderStyle BackColor="#0000C0" BorderStyle="Dotted" BorderWidth="1px" />
                    <ItemStyle HorizontalAlign="Center" Wrap="False" />
                </asp:BoundField>
      

  5.   

    你有没有给 DataKeyNames 赋值啊。如果没有赋值的话就会出现这种情况,在属性中设置一下就 OK 了
      

  6.   

    DataKeyNames="BH" 难道这句我写错了????
      

  7.   

    protected void gvCarLendInfo_PreRender(object sender, EventArgs e)
            {
                SX_QCZLXXCJ biz = new SX_QCZLXXCJ();
                t = biz.LastXUHAO();
                gvCarLendInfo.DataSource = t;
                gvCarLendInfo.DataBind();
            }
      

  8.   

    你调试下看e.CommandArgument值是多少,你的DataKeyNames才一个字段,如果e.CommandArgument超过0就超出索引了吧
      

  9.   

    是行的索引,我弄错了,不好意思.
    试下这个:
    protected void gvCarLendInfo_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                Response.Redirect(string.Format("CarLendManage.aspx?ItemBH={0}", 
               ((GridView)sender).DataKeys[Convert.ToInt32(e.CommandArgument)]));
            }