This is a migrated thread and some comments may be shown as answers.

Selected value of combobox

2 Answers 144 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Senthil ramna
Top achievements
Rank 1
Senthil ramna asked on 13 Aug 2010, 05:07 AM
How to get selected value of Radcombobox?
Like in Dropdownlist when we say
string str = Dropdownlist1.SelectedValue.ToString();

in str we can get the selected value of the dropdownlist, so the same way how can i get the selected value of Radcombobox.
cause it has the property selectedvalue but i am getting null there, can anyone help me how to do this.
i want this because based on the selected value of the first Radcombobox i am loading the next so inputs required......

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Aug 2010, 06:52 AM
Hello.


The code "RadComboBox3.SelectedValue.ToString()" worked well for me. Could you provide some more information about the scenario that you are trying?


Have you missed setting Value property of RadComboBoxItem?
              <Items>
                     <telerik:RadComboBoxItem Text="Item1" Value="1" />  . . .



-Shinu.
0
Senthil ramna
Top achievements
Rank 1
answered on 13 Aug 2010, 07:15 AM
Okay this is the flow of how this works
I have three comboboxes okay
one is for Manager upon selection of which the Group Leader loads upon selection of which the related Associate Loads.
I was doing all this using Dropdownlist by setting the Autopostback feature as true and upon selectedindex change the corresponding Dropdown lists were loaded.
But i wanted to use RadComboboxe's ItemsRequested feature as this will make sure that postback doesn't happen and delivers better user experience.
this is how my source page looks like:

<telerik:RadComboBox ID="ddlTM" AppendDataBoundItems="true" Width="150px" OnClientSelectedIndexChanging="LoadGL"                                              runat="server" onitemsrequested="ddlTM_ItemsRequested" Skin="Web20" DropDownWidth="240px">                                                                </telerik:RadComboBox>
  
<telerik:RadComboBox ID="ddlGL" AppendDataBoundItems="true" Width="150px" OnClientItemsRequested="ItemsLoaded"                                             DropDownWidth="240px" OnClientSelectedIndexChanging="LoadAssociate" runat="server" Skin="Web20" 
onitemsrequested="ddlGL_ItemsRequested">
<Items>                                                                                  <telerik:RadComboBoxItem Text="Select" />
</Items>
</telerik:RadComboBox>
  
<telerik:RadComboBox ID="ddlAssc" AppendDataBoundItems="true" Width="150px" DropDownWidth="240px"                                                           runat="server" Skin="Web20" onitemsrequested="ddlAssc_ItemsRequested" 
OnClientItemsRequested="ItemsLoaded">
<Items>                                                                                  <telerik:RadComboBoxItem Text="Select" />                    
</Items>
</telerik:RadComboBox>

this is how my javascript looks like :

<script type="text/javascript" language="javascript">
    //global variables 
var comboGL;
var comboAssociate;
  
function pageLoad()
{
    // initialize the global variables
    // in this event all client objects 
    // are already created and initialized 
    comboGL = $find("<%= ddlGL.ClientID %>");    
    comboAssociate = $find("<%= ddlAssc.ClientID %>");
}
  
function LoadGL(combo, eventArqs)
{    
    var item = eventArqs.get_item();
    comboGL.set_text("Loading...");
    comboAssociate.clearSelection();
      
    // if selected
    if (item.get_index() > 0)
    {
        comboGL.requestItems(item.get_value(), false);                                
    }
    else
    {
     // the -Select- was chosen
        comboGL.set_text(" ");
        comboGL.clearItems();
          
        comboAssociate.set_text(" ");
        comboAssociate.clearItems();
    }
}
  
function LoadAssociate(combo, eventArqs)
{            
    var item = eventArqs.get_item();
    comboAssociate.set_text("Loading...");
      
    if (item.get_index() > 0)
    {
        comboAssociate.requestItems(item.get_value(), false);
    }    
}
  
function ItemsLoaded(combo, eventArqs)
{    
    if (combo.get_items().get_count() > 0)
    {
     // pre-select the first item
        combo.set_text(combo.get_items().getItem(0).get_text());
        combo.get_items().getItem(0).highlight();
    }
    combo.showDropDown();
}
</script>

and i am calling the pageLoad function in window.onload
<script language="javascript" type="text/javascript">
window.onload=pageLoad;
</script>

This is how my code behind looks like :

protected void ddlTM_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {
        bindTM();
    }
  
    protected void ddlGL_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {
        bindGL();
    }
  
    protected void ddlAssc_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
    {
        bindAssociate();
    }

where in the methods contain this :

public void bindTM()
    {
          
        try
        {
            DC.GetGLRadCombo(GSV.GetProjectCode(), ddlTM.SelectedValue.ToString(), ddlGL, "Select");       
        }
        catch(Exception ex)
        {
            Page.ClientScript.RegisterStartupScript(base.GetType(), "myscript", GC.Message(ex.Message.ToString()));
            EH.SendException_Mail(ex);
        }      
    }
  
    public void bindGL()
    {
        string str = string.Empty;
        //str = ddlTM.SelectedValue.ToString();
        str = ddlTM.SelectedValue;        
          
         try
         {
             DC.GetAsscRadCombo(GSV.GetProjectCode(), ddlTM.SelectedValue.ToString(), ddlGL.SelectedValue.ToString(), ddlAssc, "Select");
         }
         catch (Exception ex)
         {
             Page.ClientScript.RegisterStartupScript(base.GetType(), "myscript", GC.Message(ex.Message.ToString()));
             EH.SendException_Mail(ex);
         }
    }
  
    public void bindAssociate()
    {
        try
        {
            BindGridView();
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterStartupScript(base.GetType(), "myscript", GC.Message(ex.Message.ToString()));
            EH.SendException_Mail(ex);
        }
    }

wherein DC(dataclass).GetGLRadCombo contains this :

public void GetGLRadCombo(string strProjectCode, string strTM, RadComboBox ddl, string strDefaultVal)
    {
        using (SqlConnection conn = new SqlConnection(ConnectionClass.ConnectionString))
        {
            using (SqlDataAdapter da = new SqlDataAdapter("Gems_Sp_GetGls", conn))
            {
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.CommandTimeout = 0;
                da.SelectCommand.Parameters.AddWithValue("@Project_code", strProjectCode);
                da.SelectCommand.Parameters.AddWithValue("@TM", strTM);
                ds = new DataSet();
                da.Fill(ds);
                ddl.Items.Clear();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ddl.DataSource = ds;
                    ddl.DataTextField = "GL";
                    ddl.DataValueField = "Associate_id";
                    ddl.DataBind();
                }
                ddl.Items.Insert(0, new RadComboBoxItem(strDefaultVal));
            }
        }
    }

and DC(Dataclass).GetAsscRadCombo contains

public void GetAsscRadCombo(string strProjectCode, string strTM, string strGL, RadComboBox ddl, string strDefaultVal)
    {
        using (SqlConnection conn = new SqlConnection(ConnectionClass.ConnectionString))
        {
            using (SqlDataAdapter da = new SqlDataAdapter("Gems_Sp_GetAssc", conn))
            {
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.CommandTimeout = 0;
                da.SelectCommand.Parameters.AddWithValue("@Project_code", strProjectCode);
                da.SelectCommand.Parameters.AddWithValue("@TM", strTM);
                da.SelectCommand.Parameters.AddWithValue("@GL", strGL);
                ds = new DataSet();
                da.Fill(ds);
                ddl.Items.Clear();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ddl.DataSource = ds;
                    ddl.DataTextField = "associate";
                    ddl.DataValueField = "Associate_id";
                    ddl.DataBind();
                }
                ddl.Items.Insert(0, new RadComboBoxItem(strDefaultVal));
            }
        }
    }

so here as you can see based on the selected value of the TM in bindTM i am binding the Gl then the associate.
any help is appreciated.



Tags
ComboBox
Asked by
Senthil ramna
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Senthil ramna
Top achievements
Rank 1
Share this question
or