private const string CATEGORY = "CategoryId";
private const string SUBCATEGORY = "SubCategoryId";
private const string VIDEO = "VideoId";
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
InitializeElements();
LoadContinents();
PopulateControls();
}
private static void InitializeElements()
{
// are these true Session objects? Right now they appear to be simple variables.
Geek.XTV7_Categories_ID = string.Empty;
Geek.XTV7_Categories_Sub_ID = string.Empty;
Geek.XTV7_Videos_ID = string.Empty;
ViewState.Remove(CATEGORY);
ViewState.Remove(SUBCATEGORY);
ViewState.Remove(VIDEO);
RadGrid1.Visible = false;
}
private void PopulateControls()
{
RadGrid1.Visible = false;
if(ViewState[CATEGORY] != null && !string.IsNullOrEmpty((string)ViewState[CATEGORY]))
{
var tempCategory = (string)ViewState[CATEGORY];
LoadCountries(tempCategory);
Label4.Text = tempCategory;
var tempC1 = RadComboBox1.Items.FindByValue(tempCategory);
if(tempC1 != null) tempC1.Selected = true;
}
if(ViewState[SUBCATEGORY] != null && !string.IsNullOrEmpty((string)ViewState[SUBCATEGORY]))
{
var tempSubCategory = (string)ViewState[SUBCATEGORY];
LoadCities((tempSubCategory);
Label5.Text = tempSubCategory;
var tempC2 = RadComboBox2.Items.FindByValue(tempSubCategory);
if(tempC2 != null) tempC2.Selected = true;
}
if(ViewState[VIDEO] != null && !string.IsNullOrEmpty((string)ViewState[VIDEO]))
{
var tempVideo = (string)ViewState[VIDEO];
BindData(tempVideo);
Label6.Text = tempVideo;
var tempC3 = RadComboBox3.Items.FindByValue(tempVideo);
if(tempC3 != null) tempC3.Selected = true;
}
}
private void BindData(string videoId)
{
// this line should be added before your RadGrid1.DataBind()
RadGrid1.Visible = true;
//keep your existing logic, but add the following block somewhere in this method...
#region Session Variables
Geek.XTV7_Categories_ID = (string)ViewState[CATEGORY];
Geek.XTV7_Categories_Sub_ID = (string)ViewState[SUBCATEGORY];
Geek.XTV7_Videos_ID = (string)ViewState[VIDEO];
#endregion
}
#region RadComboBox SelectedIndex Changed
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
ViewState.Remove(CATEGORY);
ViewState.Remove(SUBCATEGORY);
ViewState.Remove(VIDEO);
ViewState.Add(CATEGORY, RadComboBox1.SelectedValue.Trim());
PopulateControls();
}
protected void RadComboBox2_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
ViewState.Remove(SUBCATEGORY);
ViewState.Remove(VIDEO);
ViewState.Add(SUBCATEGORY, RadComboBox2.SelectedValue.Trim());
PopulateControls();
}
protected void RadComboBox3_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
ViewState.Remove(VIDEO);
ViewState.Add(VIDEO, RadComboBox3.SelectedValue.Trim());
PopulateControls();
}
|