Fill dropdownlist from stored procedure Error: was out of range of valid values

narue1992

For some reason the dropdownlist within my DataGrid gives me the error:

Specified argument was out of the range of valid values.
Parameter name: index

from line:

 CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataSource = rdr

I've seen this code setup work before so not sure what I am missing. My templateColumn is the 2nd column in the DataGrid.

Vb.net

Sub dg_Edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
    fillGroups()
End sub

Sub fillGroups()

    Using con2 As New MySqlConnection

        con2.ConnectionString = GetconnString(strFloor, lblDB.Text)

        Dim cmd2 As New MySqlCommand()
        con2.Open()
        cmd2.Connection = con2
        cmd2.CommandText = "stp_Select_GroupNames"

        cmd2.CommandType = System.Data.CommandType.StoredProcedure

        Dim rdr As MySqlDataReader

        rdr = cmd2.ExecuteReader

        CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataSource = rdr
        CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataValueField = "ID"
        CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataTextField = "GroupName"
        CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList).DataBind()
        rdr.Close()
        con2.Close()
    End Using
End sub

ASP.net

<asp:TemplateColumn HeaderText="'Group'" ItemStyle-Width="225" FooterStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
         <FooterTemplate>
            <asp:DropDownList ID="ddlAddGroup" runat="server" />
         </FooterTemplate>
         <ItemTemplate>
             <%#Container.DataItem("GroupName")%>
         </ItemTemplate>
         <EditItemTemplate>
             <asp:DropDownList ID="ddlEditGroup" runat="server" />
          </EditItemTemplate>
   </asp:TemplateColumn>

Update

Stored procedure

CREATE DEFINER=`root`@`%` PROCEDURE `stp_Select_GroupNames`()
BEGIN
SELECT ID, GroupName from tblg;
END  

When I run a dataset off the stored procedure I return a count so I know I am getting records returned as well.

narue1992

Current workaround:

So to fill footer you use:

Sub fillAddGroups()
    Dim ds As DataSet = getGroups()
    Dim dd As DropDownList = CType(dgAdmins.Controls(0).Controls(dgAdmins.Controls(0).Controls.Count - 1).Controls(0).FindControl("ddlAddGroup"), DropDownList)
    dd.DataSource = ds
    dd.DataValueField = "ID"
    dd.DataTextField = "GroupName"
    dd.DataBind()
End Sub

To fill dropdown that shows after clicking the edit button you do:

Sub dg_Edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
    Dim intempId As Integer
    Dim strGroup As String = ""
    intempId = CType(e.Item.Cells(0).FindControl("lblEmployeeNumber"), Label).Text
    strGroup = CType(e.Item.Cells(0).FindControl("lblGroup"), Label).Text
    dgAdmins.EditItemIndex = e.Item.ItemIndex
    sdsGroups.ConnectionString = GetconnString(strF, lblDB.Text)
    ShowEmpTable(intempId)
    fillAddGroups()
End Sub

where sdsGroups is a SqlDataSource in HTML:

<asp:SqlDataSource ID="sdsGroups"
               ProviderName="MySql.Data.MySqlClient" SelectCommandType="StoredProcedure" SelectCommand="stp_Select_FloortblGroupNames" runat="server" />

Gridview modifications

<asp:TemplateColumn HeaderText="'Group'" ItemStyle-Width="225" FooterStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
      <FooterTemplate>
          <asp:DropDownList ID="ddlAddGroup" runat="server" />
            </FooterTemplate>
                <ItemTemplate>
                   <asp:Label ID="lblGroup" Text='<%#Container.DataItem("GroupName")%>' runat="server" />
                </ItemTemplate>
             <EditItemTemplate>
                <asp:DropDownList ID="ddlEditGroup" runat="server" DataSourceID="sdsGroups" DataTextField="GroupName" DataValueField="ID"/>
              </EditItemTemplate>
       </asp:TemplateColumn>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error when importing data from CSV ,"Specific argument was out of the range of valid values"

From Dev

Error: Specified argument was out of the range of valid values. in RowDataBound Gridview

From Dev

Cascading DropDownList with Stored Procedure

From Dev

Fill Dropdownlist using values in ListItem is giving error

From Dev

Separating out values in column inside Stored Procedure

From Dev

MAMP Stored Procedure: Commands out of sync error

From Dev

Specified argument was out of the range of valid values - RowDataBound

From Dev

Writing HTML out from a stored procedure and emailing it

From Dev

How To Fill All Null Values In Table with Stored Procedure

From Dev

Nuget Error:Specified argument was out of the range of valid values. Parameter name: supportedFrameworks

From Dev

'Specified cast is not valid' error on call to SQL Server stored procedure

From Dev

Using LINQ to get values from Stored Procedure

From Dev

Returning multiple values from sql stored procedure

From Dev

Returning multiple values from sql stored procedure

From Dev

Update table in a trigger with values from stored procedure

From Dev

Fill List box with result from stored procedure C#

From Dev

Stored Procedure timing out

From Dev

Stored procedure OUT as CLOB

From Dev

Return error message from stored procedure

From Dev

Fill Dropdownlist with values from sql database in MVC4

From Dev

MySQL Stored procedure "DECLARE is not a valid"

From Dev

"Parameter is not an OUT parameter" error while calling stored procedure via CallableStatement

From Dev

T-SQL Stored procedure insert if exists with out parameters error

From Dev

sending date range parameter from crystal to sql stored procedure

From Java

Specified argument was out of the range of valid values. Parameter name: site

From Dev

Specified argument was out of the range of valid values. Parameter name: index

From Dev

Is return value from a stored procedure must be declared as out parameter?

From Dev

How to read different type of out parameters from oracle stored procedure?

From Dev

how to print out the data from stored procedure in oracle

Related Related

  1. 1

    Error when importing data from CSV ,"Specific argument was out of the range of valid values"

  2. 2

    Error: Specified argument was out of the range of valid values. in RowDataBound Gridview

  3. 3

    Cascading DropDownList with Stored Procedure

  4. 4

    Fill Dropdownlist using values in ListItem is giving error

  5. 5

    Separating out values in column inside Stored Procedure

  6. 6

    MAMP Stored Procedure: Commands out of sync error

  7. 7

    Specified argument was out of the range of valid values - RowDataBound

  8. 8

    Writing HTML out from a stored procedure and emailing it

  9. 9

    How To Fill All Null Values In Table with Stored Procedure

  10. 10

    Nuget Error:Specified argument was out of the range of valid values. Parameter name: supportedFrameworks

  11. 11

    'Specified cast is not valid' error on call to SQL Server stored procedure

  12. 12

    Using LINQ to get values from Stored Procedure

  13. 13

    Returning multiple values from sql stored procedure

  14. 14

    Returning multiple values from sql stored procedure

  15. 15

    Update table in a trigger with values from stored procedure

  16. 16

    Fill List box with result from stored procedure C#

  17. 17

    Stored Procedure timing out

  18. 18

    Stored procedure OUT as CLOB

  19. 19

    Return error message from stored procedure

  20. 20

    Fill Dropdownlist with values from sql database in MVC4

  21. 21

    MySQL Stored procedure "DECLARE is not a valid"

  22. 22

    "Parameter is not an OUT parameter" error while calling stored procedure via CallableStatement

  23. 23

    T-SQL Stored procedure insert if exists with out parameters error

  24. 24

    sending date range parameter from crystal to sql stored procedure

  25. 25

    Specified argument was out of the range of valid values. Parameter name: site

  26. 26

    Specified argument was out of the range of valid values. Parameter name: index

  27. 27

    Is return value from a stored procedure must be declared as out parameter?

  28. 28

    How to read different type of out parameters from oracle stored procedure?

  29. 29

    how to print out the data from stored procedure in oracle

HotTag

Archive