希望有人可以提供幫助。我有一個從DB獲得的對象列表。 我想上的負載,只有在列表中添加的前十到CheckBoxList的。然後用Next_click,我想添加下十個,等等。如果用戶點擊Prev,我想添加前10個。所以本質上它是通過CheckBoxlist進行分頁。顯示只有10從列表的結果和未來10與按鈕單擊
這是多麼我已經嘗試過了,沒有成功,它不會引發任何錯誤。只是不做我想做的事情。我希望它有可能。
在頁面加載這些聲明:
QuestionHandler quest = null;
protected List<QuestionView> questions = null;
int countP1 = 0;
int countP2 = 10;
這是binddata方法:
CheckBoxList1.Items.Clear();
questions = quest.GetQuestions();
List<string> display = new List<string>();
int c = 0;
foreach (QuestionView qsD in questions)
{
if (countP1.ToString().All(char.IsDigit) && countP2.ToString().All(char.IsDigit))
{
if (c >= countP1 && c <= countP2)
{
display.Add(qsD.QuestionID.ToString());
}
c++;
}
}
questions = null;
questions = new List<QuestionView>();
foreach(string s in display)
{
QuestionView q = new QuestionView();
q = quest.GetSelectQ(s);
questions.Add(q);
}
然後將其添加到CheckBoxList的(不要對長字符串,其預製表憂慮):
foreach (QuestionView qs in questions)
{
ListItem item1 = new ListItem();
item1.Text = "<table class=\"table\" style=\"border: 3px solid #8AC007;\"><tr><td>Title: </td><td width=\"300px\">" + qs.Title + "</td><td>|</td><td>Marks: </td><td width=\"300px\">" + qs.Mark + "</td><td>|</td><td>Type: </td><td width=\"300px\">" + qs.TypeID + "</td></tr><tr><td>Subject:</td><td>" + qs.SubjectID + "</td><td>|</td><td>Topic: </td><td>" + qs.TopicID + "</td><td>|</td><td>Rating: </td><td></td></tr></table>";
item1.Value = qs.QuestionID.ToString();
CheckBoxList1.Items.Add(item1);
}
下點擊:
protected void btnNext_Click(object sender, EventArgs e)
{
countP1 = countP1 + 10;
countP2 = countP2 + 10;
BindData();
}
的上一個點擊:
protected void btnPrev_Click(object sender, EventArgs e)
{
countP1 = countP1 - 10;
countP2 = countP2 - 10;
BindData();
}
希望有人明白我的意思,可以幫助,謝謝你在前進,隨時問我這個問題,如果你需要。 這一切都在更新面板。
最後,這是怎麼顯示在CheckBoxList的樣子:
我會把這個放在哪裏?問題是QuestionView對象的列表。我以前從來沒有使用過這種語法,所以我只是說,像下一頁的問題= getquestions(1),然後questions = getquestions(2)?或者我理解這個錯誤? – Cleaven
@Cleaven - 這是正確的,我已經更新了我的答案,包括一些更多的細節。 –
謝謝你的幫助,我確信這會起作用:) – Cleaven