Guest User

Guest User

  • Tech Writer
  • 271
  • 16.6k

join 2 tables bind in dropdown in asp.net

Oct 14 2020 7:29 AM
hi Experts,
 
my scenario is i have two different tables and i want bind in dropdown according to user Id....
  1. <body>  
  2. <form id="form1" runat="server">  
  3. <div>  
  4. <table>  
  5. <tr>  
  6. <td>Security Question1</td>  
  7. <td>  
  8. <asp:DropDownList ID="ddlQuestion" runat="server" AppendDataBoundItems="true">  
  9. </asp:DropDownList>  
  10. <asp:TextBox ID="TxtAnswer" runat="server"></asp:TextBox>  
  11. </td>  
  12. <tr>  
  13. <td>  
  14. <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />  
  15. </td>  
  16. </tr>  
  17. <tr>  
  18. <td>  
  19. <asp:Label ID="lblerror" runat="server"></asp:Label>  
  20. </td>  
  21. </tr>  
  22. </table>  
  23. </div>  
  24. </form>  
  25. </body>  
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. if (!IsPostBack)  
  4. {  
  5. bindSecQue();  
  6. }  
  7. }  
  8. private void bindSecQue()  
  9. {  
  10. using (schoolEntities6 context = new schoolEntities6())  
  11. {  
  12. List<SecurityModel> newlist = (from c in context.SecurityQuestionDetails  
  13. join sq in context.SecurityQuestions on c.SecQueId equals sq.Id  
  14. where c.UserId == Id  
  15. select new SecurityModel  
  16. {  
  17. Id = c.Id,  
  18. SecQue = sq.SecQue,  
  19. SecQue2 = sq.SecQue2,  
  20. SecQueId = c.SecQueId  
  21. }).ToList();  
  22. ddlQuestion.DataTextField = "SecQue";  
  23. ddlQuestion.DataValueField = "SecQueId";  
  24. ddlQuestion.DataBind();  
  25. ddlQuestion.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Select"));  
  26. }  
  27. }  
I am using this scenario but didn't show any data in frontend...and when I give static UserId == 1..it's showing...

Answers (2)