0
ページロードにバインドされたラベルとチェックボックスを含むネストされたASPデータリストがあります。ASP.NETデータリスト内のチェックボックスを表示/非表示
バインディング中に、文字列をデータリストバインドメソッドに解析します。この文字列の値がの場合は、ネストされたデータリストの各項目にチェックボックスが表示されるようにします。
値はではなく、1ではないです。
ただし、コードがコンパイルされて実行されます。文字列の値は1と検出されますが、チェックボックスは表示されません。私は間違って何をしていますか?これをどうすれば解決できますか?
データリスト:
<asp:DataList runat="server" id="dgQuestionnaire" DataKeyField="QuestionID" CssClass="confirm">
<ItemTemplate>
<div class="content_box" id="added_question">
<h3>Question <asp:Label ID="lblOrder" runat="server" Text='<%# Container.ItemIndex + 1 %>'></asp:Label></h3>
<p>Question Type</p>
<p><%# DataBinder.Eval(Container.DataItem, "QuestionText") %></p>
<asp:DataList ID="nestedDataList" runat="server">
<ItemTemplate>
<asp:CheckBox runat="server" ID="sampleCheckbox" Visible="false" />
<p class="confirm_answer new"><%# DataBinder.Eval(Container.DataItem, "AnswerTitle") %></p>
</ItemTemplate>
</asp:DataList>
</div>
</ItemTemplate>
</asp:DataList>
そしてここでは、コードが背後にある:
public void BindParentDataList(int questionnaireID)
{
// populate the datalist with items from the datatable.
SendData = new OsqarSQL();
DT = SendData.GetQuestionNameDataList(questionnaireID);
dgQuestionnaire.DataSource = DT;
dgQuestionnaire.DataBind();
// each item in the datalist call BindNestedDataList method.
foreach (DataListItem Item in dgQuestionnaire.Items)
{
BindNestedDataList(Item.ItemIndex, DT.Rows[Item.ItemIndex][2].ToString());
}
}
public void BindNestedDataList(int ItemIndex, string _questionType)
{
// get questionID value for the current datalist item and populate the answers for the question.
int questionID = Convert.ToInt32(dgQuestionnaire.DataKeys[ItemIndex]);
DT = SendData.GetAnswerTitle(questionID);
DataList nestedDataList = (DataList)dgQuestionnaire.Items[ItemIndex].FindControl("nestedDataList");
if(_questionType == "1")
{
foreach (DataListItem Item in nestedDataList.Items)
{
CheckBox checkbox = (CheckBox)Item.FindControl("sampleCheckbox");
checkbox.Visible = true;
}
}
nestedDataList.DataSource = DT;
nestedDataList.DataBind();
}