c# - ASP.Net - Displaying a collection of controls -


I am creating a simple form I have created two simple classes, questions and question questions.

Then I can make a question about some sub-classes, eg

  Private List & lt; Question & gt; With general questions, multiple checkbox questions, different behaviors and markup.  

Question is the property of the collection of questions in question, like - _ Question = New list & lt; Question & gt; (); Public listing & lt; Question & gt; Questions ({return} ask questions;}}, such as SurveyForm.aspx -

  & lt; uc: question id = "ucQuestionSection" Runat = "server">   & lt; uc: simple question id = "QLastName" runat = "server" questionTax = "last name" />  gt; & lt; / Question & gt; & lt; / UC: QuestionSection & gt;  

with my question. -

  
& lt; / div>

which is loaded on this question by QuestionSection.ascx.cs

  Secure Zero Page_Init (Object Sender, EventArgs E) {foreach (question q in question) {Pnl question. Add control (Q); }}  

I have some questions -

  1. Is this a good idea?
  2. I have some problems surrounding the postback and the perseverance of control is my thinking that these questions are not in control control, and therefore should work, however, question control is not shown on postback.
  3. Is there better control for using panel control in question? I consider using it. Control. Add, but I can not see how I can add a div to either side of the control archive.

There are some issues that you raise first, on a dynamically created control postback Do not continue properly and should be rebuilt on every postback if you want to make your events work.

Second, a better way to use control will be to create questions This control lets you define a pattern of control.

I'm not sure what the HTML definition of the question object is, but here's an example how you can use QuestionSection.ascx to modify Listview:

 < Code> & lt; Div class = "portlet-section-body form-fields" & gt; & Lt; Asp: ListView runat = "server" id = "questionist view" onitemcommand = "question health view_item command" & gt; & Lt; LayoutTemplate & gt; & Lt; Div & gt; & Lt; ASP: Place Holder ID = "Item Place Holder" Runat = "Server" /> & Lt; / Div & gt; & Lt; Div & gt; & Lt; ASP: Button Runat = "Server" id = "BNSAway" Text = "Save" CommandName = "Save" /> & Lt; Asp: button runat = "server" id = "bnCancel" text = "cancel" CommandName = "cancel" /> & Lt; / Div & gt; & Lt; / LayoutTemplate & gt; & Lt; ItemTemplate & gt; & Lt; Div class = "QuestionRow" & gt; & Lt; ASP: label runat = "server" text = '& lt;% # Eval ("question text")% & gt; AssociatedControlID = "tbAnswer" & gt; & Lt; / ASP: Labels & gt; & Lt; ASP: Text Box Runat = "Server" ID = "TBANS" & gt; & Lt; / Asp: text box & gt; & Lt; / Div & gt; & Lt; / ItemTemplate & gt; & Lt; / ASP: ListView & gt; & Lt; / Div & gt;  

It has the back code to populate it and to handle button click events. If you need any other event, try to wire the events themselves in the listover control itself, instead of the sub-rule:

  Secure Zero Page_load (Object Sender, EventAgps E } {List & lt; String & gt; Question = new list & lt; String & gt; () {"First name", "Last name", "Email address"}; Question: LISTView.DataSource = Select q from new questions {QuestionText = q}; QuestionsListView.DataBind (); } Secure Zero QuestionListView_ItemCommand (Object Sender, ListViewCommandEventArgs e) {Switch (e.CommandName) {"Save" Case: Break; Cases "Canceled": Break; }}  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -