Domanda

Specified argument was out of the range of valid values.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: value

Source Error:

Line 95:     protected void changed(object sender, GridViewPageEventArgs e)
Line 96:     {
Line 97:         GridView1.PageIndex = e.NewPageIndex;
Line 98:         //GridView1.DataBind();
Line 99:     }


Source File: c:\Users\Sartaj\Desktop\web\Websites\Asp_website_projectv1\AddInventory.aspx.cs    Line: 97

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: value]
   System.Web.UI.WebControls.GridView.set_PageIndex(Int32 value) +1318287
   AddInventory.changed(Object sender, GridViewPageEventArgs e) in c:\Users\Sartaj\Desktop\web\Websites\Asp_website_projectv1\AddInventory.aspx.cs:97
   System.Web.UI.WebControls.GridView.OnPageIndexChanging(GridViewPageEventArgs e) +133
   System.Web.UI.WebControls.GridView.HandlePage(Int32 newPage) +86
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +464
   System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +207
   System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


My gridview is->
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" AutoGenerateColumns="true" 
        BackColor="#CCCCCC" BorderColor="Black" BorderStyle="None" BorderWidth="1px" 
        CellPadding="7" CellSpacing="5" AllowPaging="True" PageSize="1" OnPageIndexChanging="changed" >
                    <PagerSettings Mode="NextPrevious" />
                    <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                    <HeaderStyle BackColor="#999999" Font-Bold="True" ForeColor="White" />
                    <PagerStyle ForeColor="#0033CC" HorizontalAlign="Center" />
                    <RowStyle BackColor="Silver" ForeColor="White" />
                    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                </asp:GridView>

**my backend code is->**
protected void addInventoryButton_Click(object sender, EventArgs e)
    {
        addInventoryAllSelectDataSource.InsertParameters[0].DefaultValue = imeiText.Text;
        addInventoryAllSelectDataSource.InsertParameters[1].DefaultValue = carrierDropDown.SelectedValue;
        addInventoryAllSelectDataSource.InsertParameters[2].DefaultValue = ((int)d1[modelDropDown.SelectedIndex][0]).ToString();
        addInventoryAllSelectDataSource.InsertParameters[3].DefaultValue = costPriceText.Text;
        addInventoryAllSelectDataSource.InsertParameters[4].DefaultValue = sellingPriceText.Text;
        addInventoryAllSelectDataSource.InsertParameters[5].DefaultValue = dateText.Text;
        addInventoryAllSelectDataSource.InsertParameters[6].DefaultValue = smartphoneRadioList.SelectedValue;
        addInventoryAllSelectDataSource.InsertParameters[7].DefaultValue = transferOrderNoText.Text;
        addInventoryAllSelectDataSource.InsertParameters[8].DefaultValue = Session["user"].ToString();
        addInventoryAllSelectDataSource.Insert();
       // gridList.Add(new AddImei(imeiText,carrierDropDown.SelectedValue,(((int)d1[modelDropDown.SelectedIndex][0]).ToString())
           // ,Convert.ToDouble(costPriceText.Text),Convert.ToDouble(sellingPriceText.Text),dateText.Text);
        //GridView1.DataSource = gridList;
        //GridView1.DataBind();
        //GridView1.DataSource = selectInventoryDataSource.Select(DataSourceSelectArguments.Empty);
        //GridView1.DataBind();
        addInventoryAllSelectDataSource.SelectCommand = "SELECT A.IMEI,A.CARRIER, F.MAKE, F.MODEL, A.COST_PRICE,A.SELLING_PRICE,A.DATE,A.SMARTPHONE,A.TRANSFER_ORDER_NO,A.USER_ID FROM AddInventory AS A FULL OUTER JOIN "+carrierDropDown.SelectedValue+" AS F ON A.CARRIER_ID_INVENTORY = F.CARRIER_ID WHERE (A.IMEI = '"+imeiText.Text+"')";
        d3  = (DataView)addInventoryAllSelectDataSource.Select(DataSourceSelectArguments.Empty);
        gridList.Add(new AddImei(d3[0][0].ToString(), d3[0][1].ToString(), d3[0][2].ToString(), d3[0][3].ToString(), Convert.ToDouble(d3[0][4]), Convert.ToDouble(d3[0][5]), Convert.ToDateTime(d3[0][6]).Date, Convert.ToBoolean(d3[0][7]), d3[0][8].ToString(), d3[0][9].ToString()));
        //AddImei ob1=new AddImei(d3[0][0].ToString(), d3[0][1].ToString(), d3[0][2].ToString(), d3[0][3].ToString(), Convert.ToDouble(d3[0][4]), Convert.ToDouble(d3[0][5]), Convert.ToDateTime(d3[0][6]).Date, Convert.ToBoolean(d3[0][7]), d3[0][8].ToString(), d3[0][9].ToString());
        GridView1.DataSource = gridList;
        GridView1.DataBind();
    }

Il problema è che quando scatto pagina successiva, non cambia pagina, clicco ancora una volta quindi pagina cambia. Dopo essere andato alla pagina successiva, clicco sul precedente cambia pagina nulla, clicco di nuovo e poi ottengo l'eccezione di cui sopra. Ho cercato di risolvere questo problema per ore, figura gergo che cosa sto facendo male qui.

È stato utile?

Soluzione

è necessario chiamare la funzione che riempiono il GridView1 dopo la PageIndexChanged evento

 protected void changed(object sender, GridViewPageEventArgs e)
 {
     GridView1.PageIndex = e.NewPageIndex;
     this.fillGridView1();
 }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top