如何在asp.net的dropdownlist中显示用户id的垂直记录 [英] how to display a perticular record of userid in dropdownlist in asp.net

查看:69
本文介绍了如何在asp.net的dropdownlist中显示用户id的垂直记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我采用了四个下拉列表,其中一个用于获取用户ID.
其他三个我正在根据特定用户的用户ID来获取记录.
我希望当用户从第一个下拉列表即useid中进行选择时,唯一的垂直记录应显示在三个垂直用户ID的下拉列表中.
我想使用asp.net.使用cshrp语言.

解决方案


 DataClassesDataContext Db =  DataClassesDataContext();
   受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
   {
       如果(!IsPostBack)
       {
            var 结果= 来自 x x  in  Db中.牛
                        选择 x;

           DropDownList1.DataSource =结果;
           DropDownList1.DataTextField = " ;
           DropDownList1.DataValueField = " ;
           DropDownList1.DataBind();

            var  resultItem = 来自 x x  in  Db中.项目
                        选择 x;

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


       }



   }
   受保护的 无效 DropDownList1_SelectedIndexChanged(对象发​​件人,EventArgs e)
   {
        var  result =(来自 x x  in  Db中.项目
                    其中 x.item_code == Convert.ToInt32(DropDownList1.SelectedValue)
                    选择 x).();
// 在此处输入您要绑定ddl的数量,但要确保您首先在Load中绑定ddlist,然后分配SelectedValue. /span>
 
       DropDownList2.SelectedValue = result.item_code.ToString();

   } 





 <   div  > ; 
      <   asp:DropDownList     ID   ="   runat   服务器"  AutoPostBack   真实" 
                     span>        ="   DropDownList1_SelectedIndexChanged" > 
      <  /asp:DropDownList  > 
      <   asp:DropDownList     ID   ="   runat   服务器" <  /asp:DropDownList  > 

  <  /div  >  


在第一个下拉列表的selectedIndexChanged事件上,从数据库中检索第一个下拉列表中所选ID的数据,然后根据需要再次绑定其他三个下拉列表.

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.

解决方案

Hi ,

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();

   }





<div>
      <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"

          onselectedindexchanged="DropDownList1_SelectedIndexChanged">
      </asp:DropDownList>
      <asp:DropDownList ID="DropDownList2" runat="server">
      </asp:DropDownList>

  </div>


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.


这篇关于如何在asp.net的dropdownlist中显示用户id的垂直记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆