specified argument was out of the range of valid values parameter name: value

 hello everyone, i need your help.. i have a gridview that has a delete button, this gridview is inside a parent gridview. my problem now is when i delete the row(the child griview will always contain one row only)  it gave me an error stating that the specified argument was out of range of valid values parameter name: value, after refreshing that's the only time the delete button will function correctly. what could be the possible reason for this, this error appears occasionally, i can't afford to have this error during our defense..please help....here is my code for delete 

<asp:GridView ID="GridView4" runat="server" AutoGenerateColumns="False" DataKeyNames="SubContractorID"
                            BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
                            CellPadding="4" DataSourceID="SqlDataSource7" OnRowDataBound="GridView4_RowDataBound"
                            ShowFooter="True">
                            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                            <RowStyle BackColor="White" ForeColor="#003399" />
                            <Columns>
                                <asp:TemplateField ShowHeader="False">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkBtnDelete" runat="server" CausesValidation="False" CommandName="Delete"
                                            Text="Delete"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="SubConName" SortExpression="SubConName">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SubConName") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblSubConName" runat="server" Text='<%# Bind("SubConName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="BiddingAmount" SortExpression="BiddingAmount">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("BiddingAmount") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <FooterTemplate>
                                        <b>SubTotal:</b>
                                        <asp:Label ID="lblSubTotal0" runat="server" Style="font-weight: 700"></asp:Label>
                                    </FooterTemplate>
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtSubConBid" runat="server" Enabled="False" Text='<%# Bind("BiddingAmount") %>'></asp:TextBox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField SortExpression="SubContractorID">
                                    <EditItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("SubContractorID") %>'></asp:Label>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("SubContractorID") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                        </asp:GridView>

<asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:DBSystemConnectionString %>"
                            SelectCommand="SELECT SubConProj.SubContractorID, SubContractor.SubConName, SubConProj.BiddingAmount, SubContractor.ContractorTypeID FROM SubConProj INNER JOIN SubContractor ON SubConProj.SubContractorID = SubContractor.SubContractorID WHERE (SubContractor.ContractorTypeID = @ContractorTypeID) AND (SubConProj.ProjectID = @ProjectID)"
                            DeleteCommand="DELETE FROM SubConProj WHERE SubContractorID=@SubContractorID">
                            <SelectParameters>
                                <asp:Parameter Name="ContractorTypeID" />
                                <asp:QueryStringParameter Name="ProjectID" QueryStringField="ProjectID" />
                            </SelectParameters>
                        </asp:SqlDataSource>
 
0
gurly
7/28/2008 2:56:28 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

22 Replies
552 Views

Similar Articles

[PageSpeed] 57

Hi gurly ,

Try to add

<DeleteParameters>

<asp:Parameter Name="SubContractorID" Type="Int64" />

</DeleteParameters>



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
7/31/2008 8:55:38 AM

 hello Samu Zhang -MSFT

thanks for your reply, i tried your suggestion but it still doesnt work.. i read some article regarding this same problem. some say that this happens when you are trying to delete the last row in your gridview, and that exactly when i encounter the error... i tried their solutions and nothing seems to solve my problem.. can you think of other way solving this..please help..i really need it in my thesis...deadline is fast approaching..thanks..looking forward for your next reply..

0
gurly
7/31/2008 9:26:15 AM

Hi gurly ,

After see your code again, i think the error maybe caused by here :

gurly:

<SelectParameters>

<asp:Parameter Name="ContractorTypeID" />

<asp:QueryStringParameter Name="ProjectID" QueryStringField="ProjectID" />

</SelectParameters>

Where do you get ContractorTypeID value and does the ProjectID exsist in querystring ?

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
7/31/2008 10:06:40 AM

i have a nested gridview.. i get the contractortypeID in the parent gridview and yes the projectID is existing in the query string...what could be the possible solution to this?? thanks for your reply... 

0
gurly
7/31/2008 11:20:13 AM

Hi gurly ,

gurly:
i get the contractortypeID in the parent gridview

Please ensure when you click the delete button , the parent contractortypeID can still be passed into sqldatasource.

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/1/2008 2:20:09 AM

 hi samu zhang

 

sorry for bothering you, but how can i do that... how will i test if the contractorTypeID is being passed into the sqldatasource?

0
gurly
8/1/2008 5:43:52 AM

Hi gurly ,

This is also what I concern. How do you specify the value ?

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/1/2008 6:16:08 AM

 my parent gridview and child gridview has different sqldatasource.. did i answer your concern.. so if i delete a record in my child gridview the contractortypeID will still be passed to the sqldatasource of the childgridview....

0
gurly
8/1/2008 6:28:19 AM

Hi gurly,

Your child GridView connect to one sqldatasource . And it has selecteparameters :

                            <SelectParameters>
                                <asp:Parameter Name="ContractorTypeID" />
                                <asp:QueryStringParameter Name="ProjectID" QueryStringField="ProjectID" />
                            </SelectParameters>
When the child GridView do bind operation, the sqldatasource need to get the the value for ContractorTypeID and ProjectID. You have said projectid can be retrieved from url, what I concern is that how it retrieve the value of ContractorTypeID .

When you delete one row, child GridView will re-bind it self to sqldatasource , and it need ContractorTypeID, how do you specify the value ??

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/1/2008 6:34:53 AM

 i specify it throught this code below. sqldatasource7 is the datasource of the childgridview. this is under the rowdatabound event of the childgridview

 

 

 if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlDataSource s = (SqlDataSource)e.Row.FindControl("SqlDataSource7");
s.SelectParameters[0].DefaultValue = e.Row.Cells[0].Text;
}
0
gurly
8/1/2008 6:46:37 AM

Hi gurly ,

Ok, I guess the code above is put in RowDataBound event of parent GridView control. Am I right ?

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/1/2008 6:48:59 AM

 oh right...sorry....yes it is in the row databound event of the parent gridview

0
gurly
8/1/2008 7:01:24 AM

Hi gurly ,

Do not say sorry , you are welcome .  

So when you click the delete button , how can you ensure the row databound event handler of the parent gridview get executed ? I think this cause the issue.


 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/1/2008 7:05:37 AM

 that i do not know.i think i dont have any code to do that? do i have to refresh the whole page in order for the row databound event handler of the parent gridview get executed...?

0
gurly
8/1/2008 7:08:40 AM

Hi gurly ,

gurly:
do i have to refresh the whole page in order for the row databound event handler of the parent gridview get executed...?

No, you do not need to do that .

I will put one HiddenField control at each row which value bind to ContractorTypeID , then the sqldatasource markup will be :

<SelectParameters>

<asp:ControlParameter ControlID="HiddenField1" Name="ContractorTypeID " PropertyName="Value"

Type="Int64" />

<another one parameter.....

</SelectParameters>

 

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/1/2008 7:32:48 AM

 thanks..but where will i place the hiddenfield control? will i place it on the parent pr childgirdview? also im new to hidden field and i do not know how that really works...if im causing so much time to you i'll just work on it but if you still have time can you show me how to do that?Big Smile

0
gurly
8/1/2008 7:56:03 AM

Hi gurly ,

Sure, maybe I should post my sample a little earlier, but I think it can help you to understand it further step by step.

Sample :

 

    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            SelectCommand="SELECT * FROM [country]"></asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="countryid"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="countryid" HeaderText="countryid" ReadOnly="True" SortExpression="countryid" />
                <asp:BoundField DataField="countryname" HeaderText="countryname" SortExpression="countryname" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("countryid") %>' />
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
                            SelectCommand="SELECT * FROM [city] WHERE ([countryid] = @countryid)">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="HiddenField1" Name="countryid" PropertyName="Value"
                                    Type="Int64" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="cityid"
                            DataSourceID="SqlDataSource2">
                            <Columns>
                                <asp:BoundField DataField="cityid" HeaderText="cityid" ReadOnly="True" SortExpression="cityid" />
                                <asp:BoundField DataField="cityname" HeaderText="cityname" SortExpression="cityname" />
                                <asp:BoundField DataField="countryid" HeaderText="countryid" SortExpression="countryid" />
                            </Columns>
                        </asp:GridView>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    
    </div>
    </form>

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
8/1/2008 8:05:20 AM

hi samu zhang

 

thanks for your patience..i tried your suggestion..but the error still appears...this error is driving me nuts...............i need to know the cause of this...

0
gurly
8/1/2008 9:44:20 AM

One possible source of this error - I had the same problem, sql data source, delete command on grid view throwing this useless error message... turns out in my case it was that I was using a stored procedure on the datasource to perform the delete... AND... it was affecting more than one row in the database, so I had to SET the NOCOUNT option to ON - and the problem went away... seems the @@ROWCOUNT was being used by the grid/datasource for some silly purpose. <sigh>

0
puzsol
8/20/2008 4:39:11 AM

 I have the identical code and problem like gurly has (so I am writing here). I have also stored procedure for delete like puzsol. I set the nocount option to ON but it still throws these silly error.

 

gurly did you solve this problem in any way or anyone else have any other suggestion?

 

thx

0
JohnS176
9/8/2008 8:22:55 AM

 hi johns176

 

yup i did solve it by deleting it manually using this code below..hope it will help you..

 

 

 protected void deleteSubCon(int SubConID, int ProjID)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBMainConnectionString"].ToString());
        conn.Open();
        SqlCommand conncmd = new SqlCommand("delete from subconproj where subcontractorid=@subID and projectid=@projID", conn);
        conncmd.Parameters.AddWithValue("@subID", SubConID);
        conncmd.Parameters.AddWithValue("@projID", ProjID);
        conncmd.ExecuteNonQuery();
        conn.Close();
    }

protected void GridView4_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int projID = int.Parse(Request.QueryString["ProjectID"]);

        GridView child = sender as GridView;
        
        Label SubConID = (Label)child.Rows[int.Parse(e.CommandArgument.ToString())].FindControl("Label1");
        int SubID = int.Parse(SubConID.Text);

        deleteSubCon(SubID, projID);
        GridView3.DataBind();
    }

 
  
0
gurly
9/8/2008 1:00:04 PM

 yeah! you rock. I managed to work it out too after your inspiration. Strange error though

 thx again

0
JohnS176
9/8/2008 10:18:37 PM
Reply:

Similar Artilces:

Specified argument was out of the range of valid values. Parameter name: value
I have two drop down list, one are titles, second one are title definition. after clicking titles dropdown list, second one will show the definition. it works fine when I used code below in the function BindData_Type_dropdown() type_DropDownList.DataSource = ds.Tables(0)         'type_DropDownList.DataTextField = ds.Tables(0).Columns("Title").ColumnName.ToString()         'type_DropDownList.DataValueField = ds.Tables(0).Columns("ID").ColumnName.ToString()         'type_DropDownList.Data...

Specified argument was out of the range of valid values. Parameter name: value
I am having a very difficult issue to resolve with this one. I have a GridView where I have set AutoGenerateDeleteButton to true, and I have a delete query in my DataSource. The delete query is actually a Stored Procedure. Within that stored procedure I initially just deleted the row and also deleted some related records, and also updated a related record with a timestamp. That all worked just fine. However, I then added a Cursor to the Stored Procedure that goes through all of the records in a given set and renumbers them after the delete. After adding this Cursor to the Stored Proce...

Specified argument was out of range of valid values. Parameter name:Value
Hi Guru's,  Below is my problem. I have a user control, in which I have a ajax tab control. At design time I just have the tabcontainer and depending on the id passed to the control I am generating the contents for the tab's. Basically each of the tab contains a list of items for each item a series of option buttons are presented to mark the score.  I have set eanable view state to false for tab and all the dynamically generated radio buttons and checkbox's, and enabled autopostback to ture, when I click on any of radio button, checkbox or image b...

(Urgent) specified argument was out of the range of valid values. Parameter name: Value
Hi  i have a datagrid in a user control which has pagin and sorting enabled and the data loads fine.. I am calling this UserControl in a tab panel using Ajax.. But when I Try to sort and page in my tab Panel...i get an error saying  specified argument was out of the range of valid values. Parameter name: Value Hope u can help me solve it.. I am dynamically generating the Tabpanel and passing the valid values to load the user control.. but when i try to page and sort i get a popup with the above error.. Any help will be appreicated. Regards Karen Golden rule about ...

Error:
Can anyone help me, I am getting the following error whilst attempting to retrieve data from an Access DB: Specified argument was out of the range of valid values. Parameter name: value I receive this error from a method which uses a select statement to retrieve data into a datareader, and then I place the value of each of the columns into variables. I have another method before this one which is identical, except for the select statement, and it gives me no errors at all. Here is my code: 'create the connection string objects Dim connstr As String co...

critical error has occurred.Specified argument was out of the range of valid values. Parameter name: value
In Debug mode my cutome module is working well. After that i created a zip file to upload the module and also i deleted my tables and store procedures.When I upload my zip file there is no error, Table and All the storeprocedures are installed  in my database.I don't know what is the problem.The error message is this The problem could be that you did not set valid default values for you module settings.Have a look at this.Best regardsHans-PeterDNNPortal German DotNetNuke Community Thank you very muchI reolve that problem by setting the default settings.Now i have one more probl...

(urgent) How do i handle this error in tabs: ( specified argument was out of the range of valid values. Parameter name: Value)
Hi   My user control consisted of a datagrid and in that datagrid i was diplaying the plans for that particular user.. My user control consits of paging and sorting but when i click on those pages no and sort by column name i get and error in the form of an popup window but the pagin and the sorting is been handled by the User control...  specified argument was out of the range of valid values. Parameter name: Value   What should i do to solve it Regards KAren...

Specified argument was out of the range of valid values. Parameter name: Hour, Minute, and Second parameters describe an unrepresentable DateTime.
This error frequently occurs when run OleDbCommand.ExecuteReader to query data from Oracle database and then bind to the DataGrid. In sql select statement has no any datatype date column. I use Oracle Provider for OLE DB. Check out my post on storing dates in Oracle at http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=341221...

Error adding node
 I have a recordset that I loop thru adding nodes to my treeview.Well at around record # 123 out of 500 or so, I get this error adding child node :"Specified argument was out of the range of valid values.Parameter name: Index was out of range.  Must be non-negative and less than the size of the collection." The node I'm adding to exists, and I can't see anything wrong w/ the data -  and it always gets hung up on the same record.*And the same code has been used 122 times already w/out issue. *Any ideas ?  my code: 'lastDivisionIndex = 1'...

Specified argument was out of the range of valid values Parameter name: index
i'm having a weird problem that isn't reproducing itself on any of my other pages. i need to run an if/else in page_load, the if statement is the text value of a label in a datalist (if the label is null do this, if it's not do that) - my datalist and sqldatasource code looks like this:  <asp:DataList ID="DataList1" runat="server" DataSourceID="iplist"> <ItemTemplate> ip: <asp:Label ID="ipLabel" runat="server" Text='<%# Eval("ip&...

Specified argument was out of the range of valid values. Parameter name: index
This is the error I'm getting. I will paste my code below: " DeleteCommand="DELETE FROM [Friends] WHERE [FriendName] = @FriendName" SelectCommand="SELECT * FROM [Friends] WHERE (([FriendName] = @FriendName))" UpdateCommand="UPDATE [Friends] SET [UserName] = @UserName, [UserID] = @UserID, [IP] = @IP, [AddedOn] = @AddedOn, [FriendName] = @FriendName, [IsApproved] = @IsApproved WHERE [FriendID] = @FriendID"> ...

Specified argument was out of the range of valid values. Parameter name: options
when i  try running a  webform i got this error:Specified argument was out of the range of valid values. Parameter name: optionsi dont where the error originated since i didnt put any control on the page i just run a plain webform.. but during the page load the error occured..any help with thi??...thnks in advance guy i keep on  posting this thread but  no reply even one. Need to see the code....Zath i didnt wrote any code just a plain webform no control or whatever the stack trace error is this:  Server Error in '/first' Application. Specified argument wa...

Specified argument was out of the range of valid values. Parameter name: index
hi i wrote the following code: System.Web.UI.WebControls.Image z=new System.Web.UI.WebControls.Image(); z.Width=100; Table1.Rows[0].Cells[0].Controls.Add(c);and i get this error Specified argument was out of the range of valid values. Parameter name: index i guess its becuse the table size is not initialized, if so i cant find away to do it....does someone have an idea whats the problem?? thanks So the Table doesn't have any rows or cells added yet? If thatr's the case, you'd either put them declaratively there before indexing to the collections (in aspx) or add them dynamically&...

Specified argument was out of the range of valid values. Parameter name: index
I am getting an error on this statement within the code(below): Line 109: Dim UserID as TextBox = e.Item.Cells(1).Controls(0). I don't know if it has anything to do with that I am not updating the UserID at all. But I am not recieving the UserID anywhere except when the data is binded in the datagrid. The UserID is read only so it cannot be changed. I am just changing little things like the name, emailaddress. Any suggestions?? I am just trying to run a simple call to a datagrid where I can Edit, Update and Cancel the information in the grib. Thanks Sub Page_Load(sen...

Web resources about - specified argument was out of the range of valid values parameter name: value - asp.net.presentation-controls

Obama declares emergency in Michigan over bad water: White House
Reuters Obama declares emergency in Michigan over bad water: White House Reuters WASHINGTON U.S. President Barack Obama declared a state of ...

American missionary among dead in Burkina Faso hotel attack
NEW YORK (AP) — The mother-in-law of an American missionary confirmed Saturday that he was among those killed after al-Qaida fighters attacked ...

Tightening Clinton-Sanders battle raises stakes for Democratic debate
By John Whitesides CHARLESTON, S.C. - Tightening polls and rising tensions between White House rivals Hillary Clinton and Bernie Sanders could ...

New England Patriots QB Tom Brady set to play in 10th AFC title game - New England Patriots Blog- ESPN ...
Tom Brady's 302 passing yards lead the New England Patriots to their fifth consecutive AFC Championship Game.

Jakarta attacks claim third victim: police
The militant attacks in Indonesia's capital have claimed a third victim, with a man dying overnight from gunshot wounds to the head, police said ...

FX CEO John Landgraf updates his forecast on 'too much TV,' talks Netflix
The man who ignited the “too much television” discussion six months ago has an update to his thoughts on the state of television.FX Chief Executive ...

7 Days: A week of iOS goodness, a VR rollercoaster, and the wonders of Windows 10 Mobile
From the end of 8 and the power of R, to Continuum coolness, PC sales slides, HoloLens battery life, and Microsoft's iPad Pro put-down, it's ...

Celine Dion's brother dies of cancer only days after her husband
Two days after Céline Dion's husband René Angélil died, it has emerged that her brother, Daniel Dion, also lost his battle with cancer. In a ...

‘Star Wars: Episode 8’ Spoilers: J.J. Abrams Could Have Already Hinted At Rey’s Real Identity, But Reveal ...
Star Wars: Episode 8 is still more than a year and a half away, but there are already some major spoilers leaking about one of the biggest mysteries ...

Obama unveils wage insurance plan to spur job seekers
U.S. President Barack Obama on Saturday laid out a plan to help support the income of workers who lose their jobs and end up in lower paying ...

Resources last updated: 1/17/2016 7:20:30 AM