template column containing user control & paging query

C

Cole Trickle

Hello all...
I have a TemplateColumn containing a UserControl

tc = new TemplateColumn();
tc.HeaderText = "Select";
tc.ItemTemplate = Page.LoadTemplate("UserControls/QuestionCheckBox.ascx");
tc.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
ctlUnlinkedQuestions.Columns.Add(tc);

The user control contains just one <asp:checkbox>

Now the DataGrid is set to page and each time I change the page I attempt to
store the chosen items in a ViewState variable...However, when I query the
checkbox's checked value it is always false?!?!? (code below)

private void ctlUnlinkedQuestions_PageIndexChanged(object source,
DataGridPageChangedEventArgs e) {
ArrayList choices = null;

// Container for references of questions chosen
if(ViewState[PageHelper.VS_UNLINKED] == null){
choices = new ArrayList();
}else{
choices = (ArrayList) ViewState[PageHelper.VS_UNLINKED];
}

// Loop through datagrid looking for checked rows
for(int i = 0; i < this.ctlUnlinkedQuestions.Items.Count; i++){
QuestionCheckBox qcb = (QuestionCheckBox)
this.ctlUnlinkedQuestions.Items.Cells[0].Controls[0];
if(((CheckBox) qcb.Controls[0]).Checked == true){
// Add reference of question to array if not already present
if(choices.Contains(qcb.Reference) == false){
choices.Add(qcb.Reference);
}
}
}

// Store the array in the ViewState
ViewState[PageHelper.VS_UNLINKED] = choices;

// Change DataGrid to new page
ctlUnlinkedQuestions.CurrentPageIndex = e.NewPageIndex;
if(ctlUnlinkedQuestions.CurrentPageIndex == (int)Session["pageUnlink"]){
ctlUnlinkedQuestions.SelectedIndex = (int)Session["indexUnlink"];
}else{
ctlUnlinkedQuestions.SelectedIndex = -1;
}

// Bind questions to DataGrid
LoadCourseQuestions();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top