Click here to Skip to main content
14,931,811 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I have two dropdown ddlCountry and ddlState and one button Submit.

While ddlstate is in update panelwhile 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
XML
<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>


XML
<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.
JavaScript
<pre lang="Javascript">function selectRow(objTR)
{
    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());    
}


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.
JavaScript
string stateDescription = Request["__EVENTARGUMENT"];
ddlState .Items.FindByText(stateDescription ).Selected = true;//for highliting the repeater value and dropdown value match and selected


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.
Posted
Updated 25-May-12 10:06am
v15
Comments
Jim Jos 25-May-12 7:22am
   
Not sure why you need to use _dopostback which is not meant for calling by programmers!! Could you cut and paste the entire code?
[no name] 25-May-12 7:25am
   
@JimJos:I am using postback for highliting the repeater cell value and dropdown value match and getting selected and after that i have to edit ddlcountry text or ddlstate text and fire update query. In my case __doPostback is necessary above code is the current scenario
Jim Jos 25-May-12 8:28am
   
No probs.. If you put your entire code I ll able be understand your requirement. Rightnow it is still confusing..
[no name] 25-May-12 8:42am
   
I HAVE UPDATED MY FULL SOURCE CODE SEE ABOVE
Jim Jos 25-May-12 9:02am
   
Sorry to bother you agian! but the code is incomplete! I need to simulate your app to give you a better result!!
[no name] 29-May-12 4:01am
   
Whts up Jim...Now check the code
Jim Jos 29-May-12 4:07am
   
OK I ll get back to you asap
[no name] 25-May-12 9:12am
   
Now see JimJos
Jim Jos 29-May-12 4:17am
   
I also need the code in 'repeaterList_ItemDataBound' event.. do you have some code in there?
[no name] 29-May-12 4:30am
   
No i have not implemented yet its just blank evnt with no code on server side
Jim Jos 29-May-12 5:37am
   
Just confirm my understanding.. the repeater control is listing some rows.. if you click on a row the corresponding dropdownlists also should highlight the values in the selected row is that correct?
[no name] 29-May-12 5:51am
   
yes u r right
[no name] 29-May-12 5:52am
   
if country is same __dopostback() method is not fire and state is not highlited in ddlState dropdownlist.
Jim Jos 29-May-12 6:48am
   
You are firing do post back just to select the corresponding state is it?
[no name] 29-May-12 6:49am
   
yes
Jim Jos 29-May-12 7:05am
   
Let me summarize:

1. Repeater shows all contries and states
2. Dropdown shows country & state
3. Whenever repeater row is selected the corresponding country should be selected int he dropdown and the states within that country should be populated in states
4. Then the state in the repeater should also be selected in the dropdown..

is this your requirement? or did I miss somthing else?
[no name] 29-May-12 7:14am
   
Yes ur 100% correct
Jim Jos 29-May-12 7:18am
   
I have one question when are you populating the contents of ddlstate? during ddlcountry selectionchanged event? or somewhere else?
[no name] 29-May-12 7:21am
   
only during ddlcountry selectionchanged event
Jim Jos 29-May-12 7:42am
   
The postback event is not firing when the contry remains the same.. I mean the country drop down selected index does not change.. You need a different logic here..
[no name] 29-May-12 7:46am
   
the country drop down selected index does not change(remains same ) then event is not fire Correct...But why can u give me reason why it is not fire...And which is different logic??
[no name] 30-May-12 1:05am
   
Have u got any solution JimJos
[no name] 30-May-12 5:55am
   
Whats happen JimJos

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900