0
我有一組來自數據庫(大約36條記錄)的選擇(選項),我必須在Gridview中插入這樣一種方式,即18將在另一列中插入一列,在另一列插入18。而且,由於這些是選擇,所以列需要成爲複選框列。所以我做了什麼是我創建了一個有2列的數據表,並相應地分割數據,然後將其綁定到網格。但問題是如果問題列表有奇數的項數,即37。它是添加一個空白用我的GridView中的複選框記錄。您的幫助將不勝感激...... 見下文 代碼在我Aspx.cs提前在Asp.Net Gridview中拆分數據
DataTable dTable = new DataTable();
dTable.Columns.Add("Questionsclmn1", typeof(string));
dTable.Columns.Add("Questionsclmn2", typeof(string));
for (int item = 0; item < QuestionList.Count; item = item + 2)
{
DataRow drow = dTable.NewRow();
drow["Questionsclmn1"] = QuestionList[item].Question;
if ((item + 1) < QuestionList.Count)
drow["Questionsclmn2"] = QuestionList[item + 1].Question;
dTable.Rows.Add(drow);
}
GrdVwQuestionsList.DataSource = dTable;
GrdVwQuestionsList.DataBind();
In my Aspx file under gridview
<Columns>
<asp:TemplateField HeaderText="Please Choose the Options Below">
<ItemTemplate>
<asp:CheckBox ID="chkQuestionList1" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Questionsclmn1")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkQuestionList2" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Questionsclmn2")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
感謝。
問候, 阿赫亞
嘿謝謝馬蒂,我正在嘗試複選框列表,但沒有意識到我可以使用repeatcolumn屬性...感謝您的幫助......這是完美的作品.. – Chetan 2010-08-09 20:31:50