I am displaying question paper with radiobuttons as options. i done the paging for datagrid using datapager control. now i select radiobuttons for all questions in the first page and click on next button againg i selected radio buttons in that page too. after that i went to previous page now all radio buttons what i selected is deselected . now i want to keep all radiobuttons select mode what i selected in every page . how can i achieve this . please help me.i display the question paper using datagrid in silverlight. in silverlight there is no concept of session . so how i have to save the values of radio buttons and that question id .i am able to maintain for the radiobutton1 throught out my application. but not to remaining three radiobuttons. i am sending my xaml file and class file and xaml.cs file . can anyone please correct that code and help me
This is my xaml code file:
Source="{Binding Path=ItemSource,ElementName=dataSource}" Foreground="#FFECDFDF" Margin="0,0,0,-8" Height="19" Width="800" Grid.ColumnSpan="2" PageIndexChanged="dPager_PageIndexChanged">
This is my class file called Questions:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web;
using System.Runtime.Serialization;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Web.UI.WebControls;
using System.Collections.ObjectModel;
using System.IO.IsolatedStorage;
namespace qpdemo.Web
{
public class questions : INotifyPropertyChanged
{
public questions()
{
private const string IsSelectedPropertyName = "IsSelected";
private bool m_isSelected;
public bool IsSelected
{
get
{
return m_isSelected;
}
set
{
m_isSelected = value;
RaisePropertyChanged(IsSelectedPropertyName);
}
}
private const string IsSelectedPropertyName1 = "IsSelected1";
private bool m_isSelected1;
public bool IsSelected1
{
get
{
return m_isSelected1;
}
set
{
m_isSelected1 = value;
RaisePropertyChanged1(IsSelectedPropertyName1);
}
}
private const string IsSelectedPropertyName2 = "IsSelected2";
private bool m_isSelected2;
public bool IsSelected2
{
get
{
return m_isSelected2;
}
set
{
m_isSelected2 = value;
RaisePropertyChanged2(IsSelectedPropertyName2);
}
}
private const string IsSelectedPropertyName3 = "IsSelected3";
private bool m_isSelected3;
public bool IsSelected3
{
get
{
return m_isSelected3;
}
set
{
m_isSelected3 = value;
RaisePropertyChanged3(IsSelectedPropertyName3);
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged3;
string Question;
[DataMember]
public string QuestionName
{
get { return Question; }
set
{
Question = value;
RaisePropertyChanged("QuestionName");
}
}
string QID;
[DataMember]
public string QuestionID
{
get { return QID; }
set { QID = value;
RaisePropertyChanged("QuestionID");
}
}
string Option1;
[DataMember]
public string option1
{
get { return Option1; }
set
{
Option1 = value;
RaisePropertyChanged("option1");
}
}
private string Option2;
[DataMember]
public string option2
{
get { return Option2; }
set { Option2 = value;
RaisePropertyChanged1("option2");
}
}
private string Option3;
[DataMember]
public string option3
{
get { return Option3; }
set { Option3 = value;
RaisePropertyChanged2("option3");
}
}
string Option4;
[DataMember]
public string option4
{
get { return Option4; }
set { Option4 = value;
RaisePropertyChanged3("option4");
}
}
}
}
This is my xaml.cs file:
protected void itemsget(object sender, GetAllQuestionsCompletedEventArgs e)
{
pgcvw = new PagedCollectionView(e.Result);
dPager.PageIndex = pgcvw.PageIndex;
dPager.Source = pgcvw;
Qpdatagrid.ItemsSource = pgcvw;
}
SWAROOP PPosted Sep 7, 2011, 4:54 AM
Hi,
Try this bellow code, May be it is use full to you.
Whenever you go to next page maintain a session with selected radio buttons list like
è First store the selected radio buttons id's in to list then assign to session like bellow
ArrayList SelectedRadioButtonIds;
//maintain contacts selected in current page index.
foreach (GridViewRow row in grid.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox objCheckBox = (CheckBox)row.FindControl(radiobuttonid);
Label ContactID = (Label)row.FindControl(lblContactId);
if (objCheckBox.Checked == true)
{
if (!SelectedRadioButtonIds.Contains(ContactID.Text))
{
SelectedRadioButtonIds.Add(ContactID.Text);
}
}
else
{
Session["SelectedRadioButtonIds"] = null;
if (SelectedRadioButtonIds.Contains(ContactID.Text))
{
SelectedRadioButtonIds.Remove(ContactID.Text);
}
}
}
}
Session["SelectedRadioButtonIds"] = SelectedRadioButtonIds;
è Whenever you go to previous page populate radio buttons form previously selected. Like bellow
if (Session["SelectedRadioButtonIds"] != null)
{
ArrayList SelectedRadioButtonIds = (ArrayList)Session["SelectedRadioButtonIds"];
if (selectedContacts.Count > 0)
{
foreach (GridViewRow row in grid.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox objCheckBox = (CheckBox)row.FindControl(checkboxid);
Label ContactID = (Label)row.FindControl(lblContactId);
if (SelectedRadioButtonIds.Contains(ContactID.Text))
{
objCheckBox.Checked = true;
count++;
}
else
{
objCheckBox.Checked = false;
}
}
}
}
}