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

need to bind the data to radgrid on selected value present in the radcombobox

2 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tamkeen
Top achievements
Rank 2
Tamkeen asked on 28 Jun 2011, 06:51 AM
Hi all,
      plz give me solution for this,
that is i got one combo-box , i have all column in the combo-box(table columns),
if i select the value from combo-box i need to bind that column to the rad grid..
which displays me only one column in the grid.
thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Jun 2011, 09:50 AM
Hello Sheraj,

Try the following code snippet to achieve your scenario.

C#:
SqlCommand cmd;
flag=0;
 private void bindgrid()
{
     SqlConnection con2 = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString);         
      string strTxt = combo.SelectedValue.ToString();
       if (strTxt != "")
       {
           cmd = new SqlCommand("SELECT "+strtxt+" FROM [Employee]", con2);
       }      
        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        ad.Fill(ds);
        RadGrid2.DataSource = ds;
}
 protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
     if(flag==1)//bind only if the combobox is selected.
       {
           bindgrid();   
       }
    }
    protected void combo_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        flag=1;
        bindgrid();
        RadGrid2.Rebind();           
    }

Thanks,
Shinu.
0
Tamkeen
Top achievements
Rank 2
answered on 28 Jun 2011, 10:32 AM
Hi shinu
    thanks for you are valuable reply  its working ..
thanks,
sheraj
Tags
Grid
Asked by
Tamkeen
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Tamkeen
Top achievements
Rank 2
Share this question
or