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

  • Home
  • SEARCH
  • 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 6671941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:26:59+00:00 2026-05-26T03:26:59+00:00

I have a Formview that gets populated with SQL data when a dropdown is

  • 0

I have a Formview that gets populated with SQL data when a dropdown is selected, but when I click edit, it wants to edit the first item on the dropdown list, because technically it still thinks its on the first page. I want the paging to be linked to the drop down but I’m not exactly sure how to accomplish this. I have a many fields so I won’t post the full Formview but here’s the key parts.

Formview Item Template:

<ItemTemplate>
          <table id="FormTable">
          <tr><th>
        <asp:DropDownList ID="ProjectNameDropDown" runat="server" AutoPostBack="true"  
        DataSourceID="SqlDataSource1" 
        DataValueField="Project_Name" name="Text" OnSelectedIndexChanged="ProjectSelect" AppendDataBoundItems="true">              
        <asp:ListItem Text="Select a Project" />
        </asp:DropDownList>
        <asp:Panel ID="Panel1" runat="server" Visible="false">             
          </th>
          <th>
            <asp:Button ID="EditButton" runat="server" CausesValidation="False" 
                CommandName="Edit" Text="Edit" />
            &nbsp;<asp:Button ID="DeleteButton" runat="server" CausesValidation="False" 
                CommandName="Delete" Text="Delete" />
            &nbsp;<asp:Button ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="New" />                 
          </th></tr>            
           <tr><th>                
            Business Category:
          </th><td>
            <asp:Label ID="BusinessCategoryLabel" runat="server" 
                Text='<%# Bind("Business_Category") %>'
                 />
            </td></tr>
          <tr><th>
            Project Description:
          </th><td>
            <asp:TextBox ID="ProjectDescriptionLabel" runat="server" ReadOnly="true"
                Text='<%# Bind("Project_Description") %>' TextMode="MultiLine" Rows="5" />
            </td></tr>
          <tr><th>
            Operations Owner:
          </th><td>
            <asp:Label ID="OwnerLabel" runat="server" 
                Text='<%# Bind("Operations_Owner") %>' />
            </td></tr>

Code Behind:

protected void ProjectSelect(object sender, EventArgs e)
    {
        DropDownList ProjectNameDropDown = (DropDownList)FormView1.FindControl("ProjectNameDropDown");
        Panel Panel1 = (Panel)FormView1.FindControl("Panel1");
        Label BusinessCategoryLabel = (Label)FormView1.FindControl("BusinessCategoryLabel");
        TextBox ProjectDescriptionLabel = (TextBox)FormView1.FindControl("ProjectDescriptionLabel");
        Label OwnerLabel = (Label)FormView1.FindControl("OwnerLabel");
        Label StakeholderLabel = (Label)FormView1.FindControl("StakeholderLabel");
        Label ReqOrgLabel = (Label)FormView1.FindControl("ReqOrgLabel");
        Label PriorityLabel = (Label)FormView1.FindControl("PriorityLabel");
        Label DateInitiatedLabel = (Label)FormView1.FindControl("DateInitiatedLabel");
        Label ReqCompletionDateLabel = (Label)FormView1.FindControl("ReqCompletionDateLabel");
        Label ProjectLOELabel = (Label)FormView1.FindControl("ProjectLOELabel");
        Label OELabel = (Label)FormView1.FindControl("OELabel");
        Label PELabel = (Label)FormView1.FindControl("PELabel");
        Label EMLabel = (Label)FormView1.FindControl("EMLabel");
        Label PARCHLabel = (Label)FormView1.FindControl("PARCHLabel");
        Label WindowsLabel = (Label)FormView1.FindControl("WindowsLabel");
        Label StorageLabel = (Label)FormView1.FindControl("StorageLabel");
        Label NetworkLabel = (Label)FormView1.FindControl("NetworkLabel");
        Label Unix2Label = (Label)FormView1.FindControl("Unix2Label");
        Label TSGLabel = (Label)FormView1.FindControl("TSGLabel");
        Label SANDLabel = (Label)FormView1.FindControl("SANDLabel");
        Label MOPSLabel = (Label)FormView1.FindControl("MOPSLabel");
        Label ACSROpsLabel = (Label)FormView1.FindControl("ACSROpsLabel");
        Label IMOpsLabel = (Label)FormView1.FindControl("IMOpsLabel");
        Label OSCOpsLabel = (Label)FormView1.FindControl("OSCOpsLabel");
        Label FinancialSvcsLabel = (Label)FormView1.FindControl("FinancialSvcsLabel");
        Label VantageLabel = (Label)FormView1.FindControl("VantageLabel");
        Label VoiceSysOpsLabel = (Label)FormView1.FindControl("VoiceSysOpsLabel");
        Label VoiceAppOpsLabel = (Label)FormView1.FindControl("VoiceAppOpsLabel");
        Label ACPxOpsLabel = (Label)FormView1.FindControl("ACPxOpsLabel");
        Label WFXOpsLabel = (Label)FormView1.FindControl("WFXOpsLabel");
        Label WebOpsLabel = (Label)FormView1.FindControl("WebOpsLabel");
        Label DBALabel = (Label)FormView1.FindControl("DBALabel");
        Label CapacityPlanningLabel = (Label)FormView1.FindControl("CapacityPlanningLabel");
        Label BCPLabel = (Label)FormView1.FindControl("BCPLabel");
        Label DataCenterLabel = (Label)FormView1.FindControl("DataCenterLabel");
        Label GoldsmithLabel = (Label)FormView1.FindControl("GoldsmithLabel");
        Label AmericasITOpsLabel = (Label)FormView1.FindControl("AmericasITOpsLabel");
        Label APACITOpsLabel = (Label)FormView1.FindControl("APACITOpsLabel");
        Label EMEAITOpsLabel = (Label)FormView1.FindControl("EMEAITOpsLabel");

        Panel1.Visible = true;
        if (ProjectNameDropDown.Items.FindByText("Select a Project").Selected != true)
        {




            string myConnectionString = @"Data Source=odcsgwinsql11.devcsg.com\ss2008;Initial Catalog=hulc01;Integrated Security=True";
            SqlConnection myConnection = new SqlConnection(myConnectionString);
            string MySelectQuery = "SELECT * FROM Common WHERE Project_Name = '" + ProjectNameDropDown.SelectedValue + "'";

            using (SqlCommand cmd = new SqlCommand(MySelectQuery))
            {
                cmd.Connection = myConnection;
                myConnection.Open();

                SqlDataAdapter Adapter1 = new SqlDataAdapter(cmd);
                DataSet dset = new DataSet();
                Adapter1.Fill(dset);
                BusinessCategoryLabel.Text = dset.Tables[0].Rows[0]["Business_Category"].ToString();
                ProjectDescriptionLabel.Text = dset.Tables[0].Rows[0]["Project_Description"].ToString();
                OwnerLabel.Text = dset.Tables[0].Rows[0]["Operations_Owner"].ToString();
                StakeholderLabel.Text = dset.Tables[0].Rows[0]["NonOps_Key_Stakeholder"].ToString();
                ReqOrgLabel.Text = dset.Tables[0].Rows[0]["Requesting_Organization"].ToString();
                PriorityLabel.Text = dset.Tables[0].Rows[0]["Priority"].ToString();
                DateInitiatedLabel.Text = dset.Tables[0].Rows[0]["Date_Initiated"].ToString();
                ReqCompletionDateLabel.Text = dset.Tables[0].Rows[0]["Required_Completion_Date"].ToString();
                ProjectLOELabel.Text = dset.Tables[0].Rows[0]["Project_LOE"].ToString();
                OELabel.Text = dset.Tables[0].Rows[0]["OE"].ToString();
                PELabel.Text = dset.Tables[0].Rows[0]["PE"].ToString();
                EMLabel.Text = dset.Tables[0].Rows[0]["EM"].ToString();
                PARCHLabel.Text = dset.Tables[0].Rows[0]["PARCH"].ToString();
                WindowsLabel.Text = dset.Tables[0].Rows[0]["Windows"].ToString();
                StorageLabel.Text = dset.Tables[0].Rows[0]["Storage"].ToString();
                NetworkLabel.Text = dset.Tables[0].Rows[0]["Network"].ToString();
                Unix2Label.Text = dset.Tables[0].Rows[0]["UNIX2"].ToString();
                TSGLabel.Text = dset.Tables[0].Rows[0]["TSG"].ToString();
                SANDLabel.Text = dset.Tables[0].Rows[0]["SAND"].ToString();
                MOPSLabel.Text = dset.Tables[0].Rows[0]["MOPS"].ToString();
                ACSROpsLabel.Text = dset.Tables[0].Rows[0]["ACSR_Ops"].ToString();
                IMOpsLabel.Text = dset.Tables[0].Rows[0]["IM_Ops"].ToString();
                OSCOpsLabel.Text = dset.Tables[0].Rows[0]["OSC_Ops"].ToString();
                FinancialSvcsLabel.Text = dset.Tables[0].Rows[0]["Financial_Svcs"].ToString();
                VantageLabel.Text = dset.Tables[0].Rows[0]["Vantage"].ToString();
                VoiceAppOpsLabel.Text = dset.Tables[0].Rows[0]["Voice_Sys_Ops"].ToString();
                VoiceSysOpsLabel.Text = dset.Tables[0].Rows[0]["Voice_App_Ops"].ToString();
                ACPxOpsLabel.Text = dset.Tables[0].Rows[0]["ACPX_Ops"].ToString();
                WFXOpsLabel.Text = dset.Tables[0].Rows[0]["WFX_Ops"].ToString();
                WebOpsLabel.Text = dset.Tables[0].Rows[0]["Web_Ops"].ToString();
                DBALabel.Text = dset.Tables[0].Rows[0]["DBA"].ToString();
                CapacityPlanningLabel.Text = dset.Tables[0].Rows[0]["Capacity_Planning"].ToString();
                BCPLabel.Text = dset.Tables[0].Rows[0]["BCP"].ToString();
                DataCenterLabel.Text = dset.Tables[0].Rows[0]["Data_Center"].ToString();
                GoldsmithLabel.Text = dset.Tables[0].Rows[0]["Goldsmith"].ToString();
                AmericasITOpsLabel.Text = dset.Tables[0].Rows[0]["Americas_IT_Ops"].ToString();
                APACITOpsLabel.Text = dset.Tables[0].Rows[0]["APAC_IT_Ops"].ToString();
                EMEAITOpsLabel.Text = dset.Tables[0].Rows[0]["EMEA_IT_Ops"].ToString();
            }
        }

I imagine somehow telling the Formview what page to switch to when selecting from the dropdown but I haven’t been able to figure out the coding for that. Thanks for your help!

  • 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-26T03:27:00+00:00Added an answer on May 26, 2026 at 3:27 am

    One way to do this (the way I’ve done it in the past) would be to move your databound DropDownList outside of the FormView. Then, bind your FormView to a different SQLDataSource that’s dependent on the DropDownLists SelectedValue. So you would have a DDL with all your Project Names:

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        DataSourceID="SqlDataSource1" DataTextField="Project_Name" 
        DataValueField="Project_Name">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="Your Connection String" 
        ProviderName="System.Data.SqlClient" 
        SelectCommand="SELECT DISTINCT [Project_Name] FROM [ProjectTable]">
    </asp:SqlDataSource>
    

    AND a FormView that is dependent upon what is selected in the DDL:

    <asp:FormView ID="FormView1" runat="server" AllowPaging="True" 
        DataKeyNames="Project_Name" DataSourceID="SqlDataSource2">
    ...
    </asp:FormView>
    
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="Your Connection String" 
        ProviderName="System.Data.SqlClient" 
        SelectCommand="SELECT * FROM [ProjectTable] WHERE Project_Name=@Project_Name">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="Project_Name" 
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>
    

    This way, when you click the “Edit” button in your FormView, you are editing the record you intended to edit.

    As a side-note, your Code Behind leaves you very vulnerable to SQL Injection. I’d be careful about that. Instead of using string concatenation to generate that SELECT query, you should use Parameterized queries

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

Sidebar

Related Questions

I have a textbox in a formview that gets its data from a linqdatasource
I have a formview that I select data based on values I get from
the problem is that I do have an ASP.NET TextBox in a FormView with
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
I have a ListView inside a FormView that, for some strange reason, doesn't fire
I am attempting to construct a formview that will edit two related objects at
I have a FormView (bound to an ObjectDataSource) that contains a CheckBoxList that I'd
Hi I have a drop down box that is in the edit template of
I have a DropDownList that populates a GridView according to the selected value. I
I have created my first asp.net UserControl that I will use in several places

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.