troubleshooting Question

Accessing Controls Buried Inside Other Controls

Avatar of Carla Romere
Carla RomereFlag for United States of America asked on
C#ASP.NET
2 Comments1 Solution73 ViewsLast Modified:
I have inherited a project created by someone who no longer works at my company. We are trying to make some modifications in how the application works and I have hit a snag.

I have a formview with the following structure:
<ContentPlaceHolder>
     <table>
          <tr>
               <td>
                    <asp:FormView>
                         <InsertItemTemplate>
                              <ddlSelectDistributor>
                                   <ddlDistributor>

I want to select a value in <ddlSelectDistributor> and have that populate the dropdown <ddlDistributor> to narrow down the choices the user has to scroll through to find their desired Distributor.

I have autopostback turned on for <ddlSelectDistributor>. Once they have selected a Distributor in <ddlDistributor>, I want to populate a few label fields all within the same <InsertItemTemplate>.

I've tried all the tricks I know to try but can't get the controls to see each other. I have moved the <SqlDataSource> to inside the <InsertItemTemplate> as suggested in one of my searches, but it's just not working yet.

On the <ddlSelectDistributor.OnSelectedIndexChanged> event, I have the following code currently:

    protected void ddlSelectDistributor_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList mySD = (DropDownList)FormView1.FindControl("ddlSelectDistributor");
        DropDownList myDist = (DropDownList)FormView1.FindControl("ddlDistributor");
        SqlDataSource sqlDist = (SqlDataSource)FormView1.FindControl("sqlDistributors");
        
        if (mySD.SelectedValue == "1144")
        {
            sqlDist.SelectCommand="SELECT CUSTOMER_NUMBER + '-' + LOCATION AS CUSTOMER_NUM, CUSTOMER_NAME + ' - ' + CASE SYS_STATE WHEN ' ' THEN SYS_PROVINCE ELSE SYS_STATE END + ' ' + SYS_POSTAL_CODE + ' - ' + SYS_ADDRESS_1 AS Location FROM VW_CUSTOMER_ADDRESSES WHERE (CUSTOMER_NUMBER = '1144') ORDER BY CUSTOMER_NUMBER, LOCATION";

            myDist.DataBind();
        }

        if (mySD.SelectedValue == "2335")
        {
            sqlDist.SelectCommand="SELECT CUSTOMER_NUMBER + '-' + LOCATION AS CUSTOMER_NUM, CUSTOMER_NAME + ' - ' + CASE SYS_STATE WHEN ' ' THEN SYS_PROVINCE ELSE SYS_STATE END + ' ' + SYS_POSTAL_CODE + ' - ' + SYS_ADDRESS_1 AS Location FROM VW_CUSTOMER_ADDRESSES WHERE (CUSTOMER_NUMBER = '2335') ORDER BY CUSTOMER_NUMBER, LOCATION";

            myDist.DataBind();
        }
        
    }

Open in new window


Then on the <ddlDistributor_SelectedIndexChanged> event, there is the following code:

   protected void ddlDistributor_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (((DropDownList)FormView1.Row.FindControl("ddlDistributor")).SelectedIndex == 0)
        {
            return;
        }
        string storeNbr = ((DropDownList)FormView1.Row.FindControl("ddlDistributor")).Text;
        if (storeNbr.Length > 0)
        {
            sqlSelectedDistributor.SelectParameters["CUSTOMER_NUMBER"].DefaultValue = storeNbr;
            DataView dv = (DataView)sqlSelectedDistributor.Select(DataSourceSelectArguments.Empty);
            if (dv.Table.Rows.Count == 1)
            {
                ((TextBox)FormView1.Row.FindControl("DistributorTextBox")).Text = Util.BlankForNull(dv.Table.Rows[0].ItemArray[0]);
                ((Label)FormView1.Row.FindControl("lblAddress")).Text = Util.BlankForNull(dv.Table.Rows[0].ItemArray[1]);
                ((Label)FormView1.Row.FindControl("lblStoreCSZ")).Text = Util.BlankForNull(dv.Table.Rows[0].ItemArray[2]);
                ((Label)FormView1.Row.FindControl("lblStorePhone")).Text = Util.BlankForNull(dv.Table.Rows[0].ItemArray[3]);
                ((Label)FormView1.Row.FindControl("lblStoreFax")).Text = Util.BlankForNull(dv.Table.Rows[0].ItemArray[4]);
            }
        }
        ((DropDownList)FormView1.Row.FindControl("ddlRAIssuedBy")).Focus();
    }

Open in new window


Any suggestions would be greatly appreciated.
ASKER CERTIFIED SOLUTION
markmiddlemist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 2 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 2 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004