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 8085673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:12:09+00:00 2026-06-05T18:12:09+00:00

I have two dropdown ddlCountry and ddlState and one button Submit. While ddlstate is

  • 0

I have two dropdown ddlCountry and ddlState and one button Submit.
While ddlstate is in update panel.
On submit of button value of both dropdown store in database.
And I show the data in Repeater Control.(In HTML Table structure)
ASPX CODE

<table id="tablelist" class="csstablelist" cellspacing="1" cellpadding="1">
                    <tr>
                        <td class="csstablelisttoptr">
                            ddlCountryID
                        </td>
                        <td class="csstablelisttoptr">
                            ddlCountryText
                        </td>
                        <td class="csstablelisttoptr">
                            ddlstateText
                        </td>
                    </tr>
                    <asp:Repeater ID="repeaterList" runat="server" OnItemDataBound="repeaterList_ItemDataBound">
                        <ItemTemplate>
                            <tr onclick="selectRow(this);">
                                <td class="csstablelisttd" style="display: none">
                                    <asp:Label ID="ddlCountryID" runat="server" Text='<%#Eval("ddlCountryID")%>'></asp:Label>
                                </td>
                                <td class="csstablelisttd">
                                    <asp:Label ID="ddlCountryText" runat="server" Text='<%#Eval("ddlCountryText")%>'></asp:Label>
                                </td>
                                <td class="csstablelisttd">
                                    <asp:Label ID="ddlstateText" runat="server" Text='<%#Eval("ddlstateText")%>'></asp:Label>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </table>
<asp:DropDownList ID="ddlCountry" runat="server" CssClass="csstextbox" Width="207px" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
</asp:DropDownList>
<asp:UpdatePanel ID="updatePanelState" runat="server">
    <ContentTemplate>
        <asp:DropDownList ID="ddlState " runat="server" CssClass="csstextbox" Width="177px">
        </asp:DropDownList>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnSave" runat="server" Width="80px" OnClientClick="return validateForm();" Text="Save" CssClass="cssbutton" OnClick="btnSave_Click" />


ddlCountryID | ddlCountryText | ddlstateText
1            | USA            | XYZ
2            |India           | PQR

Onclick of TR i write below (SelectRow(this)) function in javascript for highliting the repeater value and dropdown value match and getting selected.

<script type="text/javascript">
function selectRow(objTR)
{
 var ddlCountry =document.getElementById('<%=ddlCountry.ClientID %>');
 var ddlState =document.getElementById('<%=ddlState .ClientID %>');

    for (i = 0; i < ddlCountry .options.length; i++)
    {
        if (ddlCountry .options[i].text == objTR.cells[1].innerText.trim())
            break;
    }           
    ddlCountry .options[i].selected = true;

    __doPostBack(ddlCountry .id, objTR.cells[2].innerText.trim());    
}
</script>

I write ddlCountry SelectedIndexChangedEvent In code behind.

From Javascript I am firing __doPostBack() and passing ddlCountry as event target ddlStateText as event argument to SelectedIndexChangedEvent and getting value in event like this.

string stateDescription = Request["__EVENTARGUMENT"];
ddlState .Items.FindByText(stateDescription ).Selected = true;//for highliting the repeater value and dropdown value match and selected

Binding Country on pageLoad

 if(!Ispostback)
protected Void BindCountry()

{

strSQL = @"SELECT countryID,Country from Country_Master";
        DataTable dataTableCountry = null;
        dataTableCountry = objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];

        int countryID;
                string Country;     
        var dictioneryCountry = new Dictionary<int, string>();
        foreach(DataRow dr in dataTableCountry.Rows)
        {
            countryID = Convert.ToInt32(dr["countryID"]);
            Country= dr["Country"].ToString();          
            dictioneryCountry.Add(countryID,Country);
        }
        ddlCountry.Items.Clear();
        ddlCountry.DataTextField = "Value";
        ddlCountry.DataValueField = "Key";
        ddlCountry.DataSource = dictioneryCountry;
        ddlCountry.DataBind();
        ddlCountry.Items.Insert(0, new ListItem("[Select]", "-1"));
        ddlCountry.Items[0].Selected = true;
}

My problem is if I have following repeater data.

ddlCountryID | ddlCountryText | ddlstateText
1            | USA            | XYZ
2            |India           | PQR
2            |India           | MNO

When I select row number 3 that have country india and state mno then __dopostback() method is fire.

When I goes to row number 1 then __dopostback() method is fire.

When I come from row nuber 1 to 3 then method is fire correct way but when goes from row nuber 3 to 2 having country id same __dopostback() method is not fire and state is not selected from ddlstate.

  • 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-06-05T18:12:11+00:00Added an answer on June 5, 2026 at 6:12 pm

    If you debug your code, you will see that __doPostBack() is indeed working because the code in Page_Load is being executed (try setting a breakpoint here to check). The issue is that the index of your DropDownList is not changing, therefore the IndexChanged event is not fired and ddlCountry_SelectedIndexChanged never runs. When you call __doPostBack(), this not the same as manually calling ddlCountry_SelectedIndexChanged from the codebehind.

    Is there a particular reason that you would be doing a post back other than to set this dropdown list value?

    SOLUTION 1

    I would advise removing the __doPostBack() line and adding the following instead:

    var state = objTR.cells[2].innerText.trim();
    for (var i = 0; i < ddlState.options.length; i++)
    {
        if (ddlState.options[i].text == state)
        {
            ddlState.options[i].selected = true;
            break;
        }
    }
    

    SOLUTION 2

    Alternatively, if you really have to post back, you could do the following:

    a. Add a hidden button inside of your update panel like this:

    <div style="display: none">
    <asp:Button ID="btnState" OnClick="btnState_Click" runat="server" />
    </div>
    

    b. Change your javascript to do the following after selecting the country:

    document.getElementById('__EVENTARGUMENT').value = objTR.cells[2].innerText.trim();
    document.getElementById('<%= btnState.ClientID %>').click();
    

    c. Create a FilterState() function and call this from your ddlcountry indexchanged event

    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        FilterState();
    }
    
    private void FilterState()
    {
    // insert whatever filtering code you had here
    }
    

    d. Add your btnState_Click function (note that the way you were setting the selected item of ddlState before would throw an error if an item was already selected.):

    protected void btnState_Click(object sender, EventArgs e)
    {
        FilterState();
        string state = Request["__EVENTARGUMENT"];
        if (state != "")
            ddlState.SelectedValue = state;
    }
    

    SOLUTION 3

    A third solution would allow you to still use __doPostBack, and scrap the SelectedIndexChanged event altogether by putting this in the Page_Load function:

    if (IsPostBack && Request["__EVENTTARGET"] == ddlCountry.UniqueID)
    {
        FilterState();
        string stateDescription = Request["__EVENTARGUMENT"];
        if (stateDescription != "")
            ddlState.SelectedValue = stateDescription;
    }
    

    On another note, for your BindCountry function there’s no real reason to use a Dictionary, you can just bind the DataTable directly:

    strSQL = @"SELECT countryID,Country from Country_Master";
    DataTable dataTableCountry = objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];
    ddlCountry.Items.Clear();
    ddlCountry.DataSource = dataTableCountry;
    ddlCountry.DataTextField = "Country";
    ddlCountry.DataValueField = "countryID";
    ddlCountry.DataBind();
    ddlCountry.Items.Insert(0, new ListItem("[Select]", "-1"));
    ddlCountry.Items[0].Selected = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Asp.net dropdownlist in one of my form ..I have two dropdown
I have a dropdown. I need to bind with two field of datatable value
I have two dropdown lists (one dynamically populated, the other not) that determine the
I have two dropdown lists, one containing a list of countries and one for
I have two dropdowns in html. Both dropdowns are getting data mysql first dropdown
I currently have two dropdown menus, and one gets filtered when the user selects
I have two search buttons on a page, one linked to a dropdown list
I have two dropdown lists, the second should only be displayed when the value
I have two DropDown lists which are already populated from the database. If you
Form contains two dropdown lists created using code below. Both dropdown list elements have

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.