Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 Dropdownlists which cascading now i want to store the selected value of first ddl and pass it to the another ddl is their any way i can do that in the same view. Please note that the page should never refresh doing this. i think that require jquery or something but i am not sure.
C#
<div class="FormContainer">

<table>
<tr>
    <td class="Label">
        @Html.Label("*Name of District")
    </td>
     
    <td align="center">
        
        <select class="ddl" id="Districtddl">
            <option id="0">----Select District----</option>
            @foreach (System.Data.DataRow dr in FarmerRegisterFormAndPrint.Models.StoredProcedures.GetAllDistrict().Rows)
            { 
                <option @dr["DistrictId"].ToString()>@dr["DistrictName"].ToString()</option>
            }
        </select>
        <br />
        @Html.ValidationMessageFor(x => x.District)
            
    </td>
   
</tr>
@{var DistrictID = Request.Form["Districtddl"];}
<tr>
    <td class="Label">
        @Html.Label("*Name of Tehsil")
    </td>

    <td>
        
        <div class="ddl2" id="tehsil" align="center">
            @*@Html.Partial("_Tehsil")*@
            <select class="ddl" id="Tehsilddl">
                <option id="0">----Select District----</option>

I want to store the value of First DDL and pass it to DistrictDDL

                @if(Request.Form["Districtddl"]!=null)
                { 
                    foreach (System.Data.DataRow dr in FarmerRegisterFormAndPrint.Models.StoredProcedures.GettehsilAccToDistrict(DistrictID).Rows)
                    {
                        <option @dr["TehsilId"].ToString()>@dr["TehsilName"].ToString()</option>
                    }
                }
            </select>
        </div>
    </td>
</tr>
@{var TehsilId = Request.Form["Tehsilddl"];}
<tr>
    <td class="Label">
        @Html.Label("*Name of Sub Tehsil")
    </td>

    <td>
       
        <div id="Subtehsil" align="center">@*@Html.Partial("_SubTehsil", Model)*@
            <select class="ddl" id="Districtddl">
                <option id="0">----Select District----</option>
                @if(Request.Form["Tehsilddl"]!=null)
                { 
                    foreach (System.Data.DataRow dr in FarmerRegisterFormAndPrint.Models.StoredProcedures.GetsubtehsilAccToTehsil(TehsilId).Rows)
                    {
                        <option @dr["SubTehsilId"].ToString()>@dr["SubTehsilName"].ToString()</option>
                    }
                }
            </select>
        </div>

    </td>
</tr>

<tr>
Posted
Updated 16-Jul-15 19:18pm
v3

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



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