Click here to Skip to main content
15,916,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! i have taken four dropdownlist in which one i have used for fetching the userid.
Others three i am fetching the record on the basis of userid of a perticular user.
i want that when user select from first dropdownlist i.e useid the only perticular reocord should display in three dropdownlist of percticular userid.
i want to do this in asp.net.Using cshrp language.
Posted
Updated 29-Mar-12 3:42am
v4

Hi ,
C#
DataClassesDataContext Db = new DataClassesDataContext();
   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           var result = from x in Db.cates
                        select x;

           DropDownList1.DataSource = result;
           DropDownList1.DataTextField = "cate1";
           DropDownList1.DataValueField = "id";
           DropDownList1.DataBind();

           var resultItem = from x in Db.Items
                        select x;

           DropDownList2.DataSource = resultItem;
           DropDownList2.DataTextField = "Item_name";
           DropDownList2.DataValueField = "item_code";
           DropDownList2.DataBind();


       }



   }
   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       var result = (from x in Db.Items
                    where x.item_code == Convert.ToInt32(DropDownList1.SelectedValue)
                    select x).Single();
//put here as much as u want to bind ddl but make sure u bind ddlist in Load first  then assign SelectedValue .
 
       DropDownList2.SelectedValue = result.item_code.ToString();

   }




ASP.NET
<div>
      <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
          onselectedindexchanged="DropDownList1_SelectedIndexChanged">
      </asp:DropDownList>
      <asp:DropDownList ID="DropDownList2" runat="server">
      </asp:DropDownList>

  </div>
 
Share this answer
 
On the selectedIndexChanged event of the first dropdown, retrieve the data from the database for the selected id in the first dropdownlist and then bind the other three dropdowns again as required.
 
Share this answer
 

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