using System;
using Telerik.Web.UI;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class Applications_xTrain_Controls_xtv_VideoSelector : System.Web.UI.Page
{
readonly DataAccess _data = new DataAccess();
protected void Page_Load(object sender, EventArgs e)
{
//fill the continents combo
LoadContinents();
#region Session Variables
Geek.XTV7_Categories_ID = RadComboBox1.SelectedValue;
Geek.XTV7_Categories_Sub_ID = RadComboBox2.SelectedValue;
Geek.XTV7_Videos_ID = RadComboBox3.SelectedValue;
#endregion
if (Page.IsPostBack) return;
RadComboBox2.SelectedValue = Geek.XTV7_Categories_Sub_ID.ToString();
RadComboBox3.SelectedValue = Geek.XTV7_Videos_ID.ToString();
}
#region RadComboBox Databinding
protected void LoadContinents()
{
SqlConnection connection = new SqlConnection(
ConfigurationManager.ConnectionStrings["XtrainConnectionString"].ConnectionString);
SqlDataAdapter adapter = new SqlDataAdapter("SELECT Xtrain.XTV7_1_Categories.XTV7_Categories_Image, Xtrain.XTV7_1_Categories.XTV7_Categories_ID, Xtrain.XTV7_1_Categories.XTV7_Categories_Name, COUNT(Xtrain.XTV7_2_Videos.XTV7_Videos_ID) AS Videos FROM Xtrain.XTV7_1_Categories INNER JOIN Xtrain.XTV7_2_Videos ON Xtrain.XTV7_1_Categories.XTV7_Categories_ID = Xtrain.XTV7_2_Videos.XTV7_Categories_ID GROUP BY Xtrain.XTV7_1_Categories.XTV7_Categories_Image, Xtrain.XTV7_1_Categories.XTV7_Categories_ID, Xtrain.XTV7_1_Categories.XTV7_Categories_Name HAVING (Xtrain.XTV7_1_Categories.XTV7_Categories_Name LIKE N'ESRI%') AND (COUNT(Xtrain.XTV7_2_Videos.XTV7_Videos_ID) <> 0)", connection);
DataTable dt = new DataTable();
adapter.Fill(dt);
RadComboBox1.DataTextField = "XTV7_Categories_Name";
RadComboBox1.DataValueField = "XTV7_Categories_ID";
RadComboBox1.DataSource = dt;
RadComboBox1.DataBind();
//insert the first item
RadComboBox1.Items.Insert(0, new RadComboBoxItem("- Select a category -"));
}
protected void LoadCountries(string continentID)
{
SqlConnection connection = new SqlConnection(
ConfigurationManager.ConnectionStrings["XtrainConnectionString"].ConnectionString);
//select a country based on the continentID
SqlDataAdapter adapter = new SqlDataAdapter("SELECT XTV7_Categories_Sub_ID, XTV7_Categories_Sub_Name, XTV7_Categories_Sub_Available FROM Xtrain.XTV7_1_Categories_Sub WHERE(XTV7_Categories_ID = @XTV7_Categories_ID) AND (XTV7_Categories_Sub_Available = 1)", connection);
adapter.SelectCommand.Parameters.AddWithValue("@XTV7_Categories_ID", continentID);
DataTable dt = new DataTable();
adapter.Fill(dt);
RadComboBox2.DataTextField = "XTV7_Categories_Sub_Name";
RadComboBox2.DataValueField = "XTV7_Categories_Sub_ID";
RadComboBox2.DataSource = dt;
RadComboBox2.DataBind();
}
protected void LoadCities(string countryID)
{
SqlConnection connection = new SqlConnection(
ConfigurationManager.ConnectionStrings["XtrainConnectionString"].ConnectionString);
//select a city based on the countryID
SqlDataAdapter adapter = new SqlDataAdapter("SELECT XTV7_Videos_ID, XTV7_Categories_Sub_ID, XTV7_Videos_Title FROM Xtrain.XTV7_2_Videos WHERE (XTV7_Categories_Sub_ID=@XTV7_Categories_Sub_ID) AND (XTV7_VideoAvailable = 1) AND (NOT (XTV7_Videos_Title IS NULL))", connection);
adapter.SelectCommand.Parameters.AddWithValue("@XTV7_Categories_Sub_ID", countryID);
DataTable dt = new DataTable();
adapter.Fill(dt);
RadComboBox3.DataTextField = "XTV7_Videos_Title";
RadComboBox3.DataValueField = "XTV7_Videos_ID";
RadComboBox3.DataSource = dt;
RadComboBox3.DataBind();
}
#endregion
#region RadComboBox SelectedIndex Changed
protected void RadComboBox2_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
//BindData(Geek.XTV7_Categories_Sub_ID.ToString());
}
protected void RadComboBox3_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
BindData(Geek.XTV7_Videos_ID.ToString());
}
#endregion
#region Bind RadGrid with Video data
protected void BindData(string Video)
{
string sql = "";
sql +=
"SELECT XTV7_Videos_ID, XTV7_Categories_Sub_ID, XTV7_Videos_Title FROM Xtrain.XTV7_2_Videos WHERE (XTV7_Videos_ID= " +
Video + ") AND (XTV7_VideoAvailable = 1) AND (NOT (XTV7_Videos_Title IS NULL))";
DataTable dt = _data.GetDataTable(sql);
if (dt.Rows.Count > 0)
{
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
}
else
{
RadGrid1.DataSource = null;
RadGrid1.DataBind();
}
}
#endregion
#region RadComboBox Requested Items
protected void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
LoadContinents();
}
protected void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
// e.Text is the first parameter of the requestItems method
// invoked in LoadCountries method
LoadCountries(e.Text);
}
protected void RadComboBox3_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
// e.Text is the first parameter of the requestItems method
// invoked in LoadCities method
LoadCities(e.Text);
}
#endregion
#region Bind Image to Grid Value (Unrelated to Issue)
protected string GetImageUrl(int item)
{
if (item.Equals(0))
{
return "~/App_Themes/XGIS/images/LessonLevels/Beginner.png";
}
else if (item.Equals(1))
{
return "~/App_Themes/XGIS/images/LessonLevels/Intermediate.png";
}
else if (item.Equals(2))
{
return "~/App_Themes/XGIS/images/LessonLevels/Advanced.png";
}
else item.Equals("");
{
return "~/App_Themes/XGIS/images/LessonLevels/clear.gif";
}
}
#endregion
}
|