문제
<ItemTemplate>
<asp:Label runat="server"><%#DataBinder.Eval(Container.DataItem, "Question")%></asp:Label>
<asp:DropDownList runat="server" id="<%#DataBinder.Eval(Container.DataItem, "QuestionID")%>">>
<asp:ListItem value="1" text="Yes" />
<asp:ListItem value="0" text="No" />
</asp:DropDownList>
<ItemTemplate>
이것이 제가하려는 일입니다. 분명히 구현에 결함이 있지만 실제로이를 어떻게 진행하는지에 대한 정보를 찾을 수 없습니다. 모든 도움이 감사합니다.
편집 : 정확히하려는 것은이 리피터의 각 항목에 대한 드롭 다운 목록을 추가하고 양식을 제출하면 각 예/아니오 답변을 사용하여 데이터베이스에 입력하십시오. 내가 사용하는 SQLDATAREADER에는 질문 내용과 QuestionID의 두 가지 필드가 있습니다.
해결책
리피터 내부의 ID에 대한 내장 지원을 사용하는 것이 더 나을 것이라고 생각합니다. 목표가 데이터를 할당하여 데이터가 묶은 후에 적절한 제어를 쉽게 찾을 수 있도록 ID를 할당하는 경우 다음과 같은 것을 시도 할 수 있습니다.
<asp:Repeater ID="Repeater1" runat="server>
<ItemTemplate>
<asp:Label ID="QuestionID" Visible="False" Runat="server"><%#DataBinder.Eval(Container.DataItem, "FieldContent")%></asp:Label>
<asp:DropDownList ID="MyDropDownList" Runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:Repeater>
그런 다음 코드에서 원하는 레이블을 찾을 때까지 리피터의 항목을 반복 할 수 있습니다.
foreach (RepeaterItem curItem in Repeater1.Items)
{
// Due to the way a Repeater works, these two controls are linked together. The questionID
// label that is found is in the same RepeaterItem as the DropDownList (and any other controls
// you might find using curRow.FindControl)
var questionID = curRow.FindControl("QuestionID") as Label;
var myDropDownList = curRow.FindControl("MyDropDownList") as DropDownList;
}
리피터는 기본적으로 리피터 리티 템 모음으로 구성됩니다. 리피터 리 설정은 ItemTemplate 태그를 사용하여 지정됩니다. 각각의 리피터에는 리피터의 본질에 따라 서로 관련된 자체 컨트롤 세트가 있습니다.
데이터베이스에서 리피터 데이터를 가져오고 있다고 가정 해 봅시다. 각 리피터 항목은 쿼리 결과의 개별 행 데이터를 나타냅니다. 따라서 QuestionID를 레이블에 할당하고 설문지 이름을 DropDownList에 할당하면 레이블의 ID가 Droplow의 이름과 일치합니다.
다른 팁
마크 업 파일에서 컨트롤을 제거하고 리피터의 onitemDatabound 이벤트를 연결할 수 있습니까? 이 경우 원하는 ID를 할당하여 드롭 다운 컨트롤을 "수동으로"만들 수 있어야합니다.