Last post Nov 08, 2010 01:30 PM by tmmycat
Nov 08, 2010 11:24 AM|tmmycat|LINK
I want to make a field template that uses a RadioButtonList or a DropDownList and only shows a subset of choices from the related table - not all rows - is it possible and how would I do that?
If I could just see the code for the FieldTemplateUserControl.PopulateListControl() method I'm sure I could think of something, unfortunately I couldn't "see under the hood" for that method - tried looking at it in Reflector and still couldn't see the code
for that method.
The scenario where I want to use this ... I made a RadioButtonList field template that I'm using to answer survey questions. Some questions allow Yes and No and others allow Yes, No, or N/A. The Answers table contains all three choices, but depending on
the question I might just want to show Yes and No.
Another example where I want to use this is a status dropdown that only shows valid choice based on the current status. Initial status would be Draft. Then it can go to Submitted. From Submitted it could go to Approved or Rejected.
Thanks in advance!!
Nov 08, 2010 01:30 PM|tmmycat|LINK
I kind of answered my own question ... I made a field template that will only be used for this one field and I did my own databinding instead of using FieldTemplateUserControl.PopulateListControl().
In my entity template I have this:
<asp:DynamicControl ID="AnswerControl" DataField="Answer" runat="server" Mode="Edit"
protected void AnswerControl_Load(object sender, EventArgs e)
AnswerRadio_EditField answer = (sender as DynamicControl).FieldTemplate as AnswerRadio_EditField;
if (answer != null)
SurveyResponseAnswer dataItem = (answer.NamingContainer as GridViewRow).DataItem as SurveyResponseAnswer;
answer.QuestionID = dataItem.QuestionID;
I made the AnswerRadio_Edit field template with databinding code that looks like this:
TreatmentIntegrityDataContext data = new TreatmentIntegrityDataContext();
var question = data.Questions.FirstOrDefault(q => q.QuestionID == QuestionID);
if (question == null)
throw new ArgumentException("The AnswerRadio field template requires a valid QuestionID.");
RadioButtonList1.DataTextField = "AnswerText";
RadioButtonList1.DataValueField = "AnswerID";
RadioButtonList1.DataSource = question.QuestionType.QuestionTypeAllowedAnswers;
Then I used [UIHint("AnswerRadio")] for my Answer property.
I couldn't picture a way to do it more generically with a field template that I could reuse for other similar fields ... but this will still work.