nagaraju

nagaraju

  • NA
  • 87
  • 127.9k

How to maintain the state of radiobuttons in datagrid

Sep 7 2011 1:17 AM
Hi,

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:

<Grid x:Name="LayoutRoot" Background="White" Height="500">




<sdk:DataGrid x:Name="Qpdatagrid" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=dataSource, Path=Data}" LoadingRow="Qpdatagrid_LoadingRow">

<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>


<DataTemplate>
<StackPanel >
<StackPanel Orientation="Horizontal" x:Name="controls">
<sdk:Label x:Name="lbl_QID" Content="{Binding QuestionID}" />


<TextBlock Text=")"/>
<TextBlock Text="{Binding Path=QuestionName}" />
</StackPanel>
<StackPanel Orientation="Vertical" Height="100" x:Name="radio">
<RadioButton x:Name="rd1" GroupName="{Binding OptionGroup}" Content="{Binding option1}" IsChecked="{Binding IsSelected,Mode=TwoWay}"></RadioButton>
<RadioButton x:Name="rd2" GroupName="{Binding OptionGroup}" Content="{Binding option2}" IsChecked="{Binding IsSelected1,Mode=TwoWay}"></RadioButton>
<RadioButton x:Name="rd3" GroupName="{Binding OptionGroup}" Content="{Binding option3}" IsChecked="{Binding IsSelected2,Mode=TwoWay}"></RadioButton>
<RadioButton x:Name="rd4" GroupName="{Binding OptionGroup}" Content="{Binding option4}" IsChecked="{Binding IsSelected3,Mode=TwoWay}"></RadioButton>
</StackPanel>




</StackPanel>

</DataTemplate>

</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>

</sdk:DataGrid>



<sdk:DataPager x:Name="dPager" DisplayMode="FirstLastPreviousNext" PageSize="5"
RenderTransformOrigin="0.5,0.5" VerticalAlignment="Bottom"
Source="{Binding Path=ItemSource,ElementName=dataSource}" Foreground="#FFECDFDF" Margin="0,0,0,-8" Height="19" Width="800" Grid.ColumnSpan="2" PageIndexChanged="dPager_PageIndexChanged">
<sdk:DataPager.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF5F5BAD" Offset="1"/>
</LinearGradientBrush>
</sdk:DataPager.Background>
<sdk:DataPager.BorderBrush>
<LinearGradientBrush>
<GradientStop Color="#FFA3AEB9" Offset="0"/>
<GradientStop Color="#FF8399A9" Offset="0.375"/>
<GradientStop Color="#FF718597" Offset="0.375"/>
<GradientStop Color="#FFE88B09" Offset="1"/>
</LinearGradientBrush>
</sdk:DataPager.BorderBrush>

</sdk:DataPager>

<TextBlock Height="23" HorizontalAlignment="Left" Margin="394,-29,0,0" Name="textBlock1" Text="QUESTION PAPER" VerticalAlignment="Top" TextAlignment="Center" Foreground="Crimson" FontWeight="Bold" FontSize="15" />
<Button Content="Check" Height="23" HorizontalAlignment="Left" Margin="637,-34,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="Btn_Click" />

</Grid>


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;



}



Answers (1)