0

So I´m trying to create a registration page for a website where the User can register a number questions and answers. Users´ information is already on the app´s database (The number of questions the user needs to answer to register). So for example I have two users user1 and user2 each with 2 and 3 questions to register respectively. The questions are can be chosen from a dropdown list and below it there is a textbox to answer it.

So my question is, how do I populate the page for each respective user? user1 should have 2 DDLs and textboxes and user2 3 DDLs and textboxes. The reason for this is that users belong to different groups and thus have different requirements to register. I have seen from this page and this page that I may have to write my own engine?

Here is my aspx code:

<asp:ListView runat="server" ID="RegisterListView" DataKeyNames="Id" Visible="true"  >
            <LayoutTemplate>
                <table id="tblRegister"
                    style="width: 460px; background-color: lightgray" border="1">
                    <tr runat="server" id="itemPlaceholder">
                    </tr>
                </table>

            </LayoutTemplate>
            <ItemTemplate>
                <tr runat="server">
                    <td colspan="2">
                        <asp:DropDownList ID="RegisterQuestionList" runat="server" SelectMethod="RegisterQuestionList_GetData" />
                    </td>
                </tr>
                <tr runat="server">
                    <td colspan="2">
                        <asp:TextBox runat="server" />
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>

And here is my behind-code, which on pageload retrieves the user specific number of questions and the GetData method populates the drop down lists:

protected void Page_Load(object sender, EventArgs e)
    {
        using (var db = new AppContext())
        {

            var userID = Convert.ToInt32(Request.QueryString["User"]);
            userID = 9;
            var currentUser = db.Users.Find(userID);
            numQuestions = currentUser.NumQuestionsRegister;

        }
    }


    public IQueryable<QuestionPool> RegisterQuestionList_GetData()
    {
        var db = new AppContext();
        var questions = db.QuestionsPool;

        return questions;
    }

Some advise on how to approach this would be greatly appriciated. Thank you.

Curiousdev
  • 5,668
  • 3
  • 24
  • 38
Enixf
  • 87
  • 2
  • 9
  • @It'satrap you mean programmatically adding the dropdown list and textboxes with for loops? – Enixf Mar 30 '17 at 12:08
  • Yes. Check the user's group/whatever with if else statements and return accordingly – It's a trap Mar 30 '17 at 12:08
  • @It'satrap I´m fairly new with asp.net so I´m not that sure how to programmatically add the markup code. Could you enlighten me a bit on how to do this? – Enixf Mar 30 '17 at 12:21
  • You said that user's information is already in the database. Depending on that you want to ask 2/3 questions. So now fetch the info and let's say it's for user1, then show 2 DDL's otherwise show 3. This can be achieved via a simple if else block of C#. Refer this link on how to embed C# in aspx page https://msdn.microsoft.com/en-us/library/ms178135.aspx – It's a trap Mar 30 '17 at 12:38
  • @It'satrap ahhh, I see. It was more simple than I previously thought. Thank you for the help! – Enixf Mar 30 '17 at 13:12
  • Great. Glad to have helped :) – It's a trap Mar 30 '17 at 13:13

0 Answers0