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

Grid with Cascading dropdownlist with Insert/Update/Delete functionality

1 Answer 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prasanna
Top achievements
Rank 1
Prasanna asked on 14 Nov 2011, 09:36 AM
Hello,
I want to create a grid with data changes as per radiobuttonlist selection.
Then depend on that data there are checkbox control ,cascading dropdoenlist control.but as per 
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx
this link i try to create dropdownlist as per my data but it is not working.
Here is following code: 
qry = "SELECT BudgetName, Budget,GroupName,Budget.GroupId FROM Budget,mGroup " +
                                " where BudgetTypeId=(select BudgetTypeId from BudgetType where BudgetTypeName='" + HiddenField1.Value + "') and " +
                                "Budget.GroupId = mGroup.GroupId ";


                            using (SqlCommand Cmd = new SqlCommand(qry, Conn))
                            {
                                da.SelectCommand = new SqlCommand(qry, Conn);


                                DataSet myDataSet = new DataSet();


                                try
                                {
                                    da.Fill(myDataSet, "BudgetDim");
                                    da.SelectCommand = new SqlCommand("SELECT GroupId, DimensionName FROM [Dimension]", Conn);
                                    da.Fill(myDataSet, "Dimension");
                                }
                                finally
                                {
                                    Conn.Close();
                                }
                               
                                    RadGrid2.DataSource = myDataSet;
                                    RadGrid2.DataBind ();

and also when I try to assign  seperate datatabels to 2 grids but it is not showing data for second grid.
Please help me out.                              

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 16 Nov 2011, 05:03 PM
Hello Prasanna,

Where do you use this code snippet? Is it part from the NeedDataSource event handler of RadGrid? If this is the case, you should remove the DataBind() method from it, because as this help article says you should not use DataBind when performing advanced data binding.

Additionally, I do not see where you have declared your DataAdapter, to which you are assigning a SelectCommand. Also, you could put in the using statement the connection object along with its open() method instead of the SqlCommand. Thus you will not need to worry for closing the connection after, because when the program leaves the scope of the using statement it will be automatically closed and its resources will be freed.

Moreover, as you can see in this MSDN thread, when using Fill() method with string as a second parameters, you are passing the name of the source table from which you want to take data. If you make two such calls with different source tables on one DataSet you will end up with overwritten data, not two different DataSets. To overcome this, you could use second DataSet which will holds the data from the second source table.

So in conclusion, if you have followed all of the above suggestions, your code should be something similar to this:

DataSet BudgetDimDataSet = new DataSet();
DataSet DimensionDataSet = new DataSet();
using (SqlConnection conn = new SqlConnection(ConnString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(
"SELECT BudgetName, Budget,GroupName,Budget.GroupId FROM Budget,mGroup " +
" where BudgetTypeId=(select BudgetTypeId from BudgetType where BudgetTypeName='" + HiddenField1.Value + "') and " +
"Budget.GroupId = mGroup.GroupId ", conn);
adapter.Fill(BudgetDimDataSet, "BudgetDim");
adapter.Fill(DimensionDataSet, "Dimension");
}
RadGrid1.DataSource = BudgetDimDataSet;
RadGrid2.DataSource = DimensionDataSet;
}

If the case is different, share more of your code and let us know what are the issues you are experiencing.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Prasanna
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or