Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4238564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:55:16+00:00 2026-05-21T02:55:16+00:00

I had datalist and I had ddl on it and user can select value

  • 0

I had datalist and I had ddl on it and user can select value from ddl to bind datalist. When I tried to find ddl in datalist when user select value, this error apeared

Index was out of range. Must be
non-negative and less than the size of
the collection. Parameter name: index

here

DDLProduct2 = (DropDownList)DLProduct.Items[DLProduct.EditItemIndex].FindControl("DDlProduct");

so please any one help me.

private DropDownList DDLProduct2;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ProductByProductID();
            CategoryParentZero();


        }
    }
 protected void DDlProduct_SelectedIndexChanged(object sender, EventArgs e)
    {
        DDLProduct2 = (DropDownList)DLProduct.Items[DLProduct.EditItemIndex].FindControl("DDlProduct");
        if (DDLProduct2 != null)
        {
            if (DDLProduct2.SelectedIndex > 0)
            {
                using
                (SqlConnection conn = Connection.GetConnection())
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "SP_GetProductsByProductID";
                    SqlParameter ParentID_Param = cmd.Parameters.Add("@ProductID", SqlDbType.Int);
                    ParentID_Param.Value = DDLProduct2.SelectedValue;
                    ;
                    DataTable dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;
                    da.Fill(dt);
                    DLProduct.DataSource = dt;
                    DLProduct.DataBind();

                }
            }
        }

    } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:55:17+00:00Added an answer on May 21, 2026 at 2:55 am

    DLProduct.EditItemIndex should be equal to -1 because the is nothing edited

    just add an if DLProduct.EditItemIndex >= 0 before the line throwing the error

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had ddl in datalist and when I tried to bind datalist with value
Had a search around and can't seem to find any options to do this,
I had Datalist which retrieve aportion of atext from database and this text must
I had datalist and My manager told me when user select item in datalist
Had a good read through similar topics but I can't quite a) find one
Had a quick google to see if this can be done without much luck,
Had an interesting error today and couldn't find anything online about it so wondered
had a look for a guide on this but couldn't really find anything specific
I had datalist as menu that display categories and subs and I want to
Had to download Command Line Tools from Apple to get make to work, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.