1. jyothsna
    jyothsna avatar
    1 posts
    Member since:
    Jun 2011

    Posted 18 Jul 2011 Link to this post

    combobox2 changes based on combobox1. And the Rad grid will populated based on two comboboxes. when ever we change the second combobox2 selected value it shows the first value all the time and tha data in grid is not changing (combobox2 has four options date1, date2, date3 and date4. But if user changes the selection to date2 the combobox2 still shows as date1 and the data in grid is not chnaging)
    please see attached code.

    Thanks
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Security.Principal;
    using Telerik.Web.UI;
     
    public partial class _DataReview : System.Web.UI.Page
    {
         
            private DataSet searchResults = new DataSet();
            private DataSet ddlist = new DataSet();
            private DataView searchResultsView = new DataView();
             
            string strID = "";
            string strcomments = "";
            string Combobox2Date = "";
     
     
            protected void Page_Load(object sender, EventArgs e)
        {
     
                if (!Page.IsPostBack)
                {
                    PopulateRadCombobox1 ();
                    lblErrorMsg.Visible = false;
                    ViewState["Id"] = null;
     
                }
     
     
                if ((string)ViewState["Id"] != null && (string)ViewState["Id"] != "Loading...")
                {
                    RadCombobox2.Text = (string)ViewState["Id"];
                }
                
                
       }
     
            protected void btnSearch_Click(object sender, EventArgs e)
            {
                this.lblErrorMsg.Visible = false;
                string index = RadCombobox1.SelectedValue;
     
                if (index == "0" || index =="-1")
                {
                    
                    RadGrid1.Visible = false;
                    this.lblErrorMsg.Visible = true;
                                }
                else
                {
                    RadGrid1.Visible = true;
                    RadGrid1.CurrentPageIndex = 0;
                    RadGrid1.DataSource = this.bindGrid();
                    RadGrid1.DataBind();
                    btnApprove.Visible = true;
                    int searchCount = RadGrid1.Items.Count;
                    if (searchCount == 0)
                    {
                        RadGrid1.Visible = false;
                        this.lblErrorMsg.Visible = true;
                         
                    }
                }
     
            }
     
     
     
            private DataView bindGrid()
            {
                 
                using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnString"].ConnectionString))
                {
     
                    string name= RadCombobox1.Text ;
                    Date = RadCombobox2.Text ;
                    SqlCommand cmd = new SqlCommand("dbo.SP_GetDataForRadGrid", sqlCon);
                    cmd.Parameters.Add("@table_name", SqlDbType.VarChar).Value = name;
                    cmd.Parameters.Add("@Date", SqlDbType.VarChar).Value = dropboxDate;
                    cmd.CommandType = CommandType.StoredProcedure;
                    searchResults = new DataSet();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(searchResults);
                }
                return searchResults.Tables[0].DefaultView;
     
            }
     
     
     
     
            private void PopulateRadCombobox1()
            {
                using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnString"].ConnectionString))
                {
     
                    try
                    {
                        sqlCon.Open();
                        SqlCommand cmd = new SqlCommand("dbo.Sp_GetCombobox1data", sqlCon);
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
                        if (sqlReader.HasRows)
                        {
                            RadCombobox1.DataSource = sqlReader;
                            RadCombobox1.DataTextField = "name";
                            RadCombobox1.DataValueField = "id";
                            RadCombobox1.DataBind();
                            RadCombobox1.Items.Insert(0, new RadComboBoxItem("Select Name", string.Empty));
                        }
                    }
     
                    catch (SqlException ex)
                    {
                        lblErrorMsg.Text = ex.Message;
                        lblErrorMsg.Visible = true;
                    }
                    finally
                    {
                        // Close the database connection
                        sqlCon.Close();
                    }
     
                }
     
            }
     
            private void PopulateRadCombobox2(int ID)
            {
                using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnString"].ConnectionString))
                {
                    // RadDropBoxList.Items.Clear();
                    try
                    {
                        sqlCon.Open();
                        SqlCommand cmd = new SqlCommand("dbo.Sp_GetNameandLocation", sqlCon);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@Id", SqlDbType.Int).Value = ID;
                        SqlDataReader sqlReader = cmd.ExecuteReader();
     
                        if (sqlReader.HasRows)
                        {
     
                            sqlReader.Read();
                            RadCombobox2.DataSource = sqlReader;
                            RadCombobox2.DataTextField = "FilePath";
                            RadCombobox2.DataValueField = "Id";
                            RadCombobox2.DataBind();
     
                        }
     
                        else if (sqlReader.HasRows == false)
                        {
                            lblDropbox.ForeColor = System.Drawing.Color.Red;
                            lblDropbox.Text = "There is No Dropboxes";
                        }
     
                    }
     
                    catch (SqlException ex)
                    {
                        lblErrorMsg.Visible = true;
                        lblErrorMsg.Text = ex.Message;
     
                    }
                    finally
                    {
                        // Close the database connection
                        sqlCon.Close();
                    }
     
                }
     
            }
     
     
          
     
     
     
     
     
            protected void txtTitleId_TextChanged(object sender, EventArgs e)
            {
     
            }
     
     
     
                RadGrid1.CurrentPageIndex = 0;
                RadGrid1.DataSource = this.bindGrid();
                RadGrid1.DataBind();
                lblErrorMsg.Visible = true;
     
     
            }
     
     
     
     
            protected void RadGrid1_PageIndexChanged(object source, GridPageChangedEventArgs e)
            {
                RadGrid1.CurrentPageIndex = 0;
                RadGrid1.DataSource = this.bindGrid();
                RadGrid1.DataBind();
            }
     
            protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
            {
            }
     
     
            protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dataItem = e.Item as GridDataItem;
                    string Caseno = dataItem["CaseID"].Text.ToString().Trim();
                    
                }
            }
     
            protected void RadGrid1_PageSizeChanged(object source, GridPageSizeChangedEventArgs e)
            {
                RadGrid1.CurrentPageIndex = 0;
                RadGrid1.DataSource = this.bindGrid();
                RadGrid1.DataBind();
            }
     
            protected void RadGrid1_SortCommand(object source, GridSortCommandEventArgs e)
            {
                RadGrid1.CurrentPageIndex = 0;
                RadGrid1.DataSource = this.bindGrid();
                RadGrid1.DataBind();
            }
     
            protected void RadCombobox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
            {
                PopulateRadCombobox1();
            }
     
     
     
            protected void RadCombobox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
            {
                // e.Text is the first parameter of the requestItems method
                string id = e.Text.ToString();
                int Id = Convert.ToInt32(id);
                PopulateRadCombobox2 (Id);
            }
     
     
     
             
    }
  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 21 Jul 2011 Link to this post

    Hello Jyothsna,

    Since you have already opened another forum thread, lets continue the discussion there.

    All the best,
    Dimitar Terziev
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top