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

Custom Binding Grid + Combo or Drop Down

6 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 05 May 2009, 02:47 PM
Hi All,

I have only about 5 hours experiance with these controls so please be gentle. I need to get a rough demo together ASAP.
So having very little experiance with these controls... (and I only have 10 hours in ASP.NET!)

1) I presume unbound custom binding using DataTable, saving it into Session[""] is going to be the fast method for reading data? 
    I always tend to use Object models for Win32 applications, is the ObjectDataSource not more of an overhead in a ASP.NET app?

2) I need to populate a couple of unbound DropDowns. Where do I load the data?

3) How do I get a radCombo into a grid column? 

Sorry if these questions seem to cover old ground but there is a lot documentation, etc just need a few quick pointers...

Many thanks for your help...

Ian.

6 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 06 May 2009, 04:14 AM
Ian-

First of all, welcome to ASP.NET and the RadControls! You definitely can build a working demo with the RadControls in very little time- even with little ASP.NET experience (assuming you're not also new to .NET).

I suggest you spend time looking at the Quick Start Demos. They are one of the best places to find practical, easy to understand code snippets that can accelerate you learning. As for your questions:

  1. ObjectDataSource is definitely one of the best ways to do data access in ASP.NET and Session is one of the worst. Technically, these two things are apple and oranges- one is a data source, one is a storage container. If you're just looking to rapid prototype, though, try using the SqlDataSource control and bind it to the RadGrid via the DataSourceID property. This will give you lots of functionality out of the box- sorting, paging, filtering, data editing, etc. You can optimize later as you learn more about ASP.NET.
  2. For DropDowns- or RadCombobox- you can also bind them to Data Source controls for rapid prototypes. As you learn more, you can easily optimize by using LoadOnDemand features to enable "codeless" Ajax.
  3. To get the RadCombobox in a RadGrid, try checking out this demo:
    http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx
    Look at the "GridDropDownColumn." It will automatically add a RadCombobox to the grid for editing.

Hope that helps. For other answers, make sure you search the forums. There is a ton of knowledge in the forums, demos, and docs that can all help you get started!

-Todd
0
Ian
Top achievements
Rank 1
answered on 06 May 2009, 08:27 AM
Thanks Todd.

I am not new to .NET but only "do" Win32 applications. So my life is much easier most of the time ~:0)

I have checked out the examples / forums; sometimes the samples seem a little too simplistic? Just need a little quick help, I will work through the entire Courseware, etc ASAP.

On the Data Binding front. I can easily create an object model but it seemed like numerous people on forums found using the ObjectDataSource control to be quite limiting?

So, if you needed to:

1) Create a fast, optimized data source that is flexible enough for custom data binding 
2) Uses stored procedures for all select, insert, delete, update, etc

On one of the demo's (which I adapted) slightly.. is storing the DataTable in the Session[""] not good practice?

 

private DataTable Subjects  
        {  
            get 
            {  
                object obj = this.Session["Subjects"];  
                if ((!(obj == null)))  
                {  
                    return ((DataTable)(obj));  
                }  
                DataTable myDataTable = new DataTable();  
                
                myDataTable = new EntryDB().GetSubjects();  
                  
                this.Session["Subjects"] = myDataTable;  
                return myDataTable;  
            }  
        } 

 

  protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
            this.RadGrid1.DataSource = this.Subjects;  
            this.Subjects.PrimaryKey = new DataColumn[] { this.Subjects.Columns["SubjectID"] };  
        } 

 

Using the ObjectDataSource control would achieve better results? I would much rather deal with object / properties than a DataTable.

I will also need change the underlying query for a grid i.e. based on a set of radio buttons, etc  But surely the overhead of creating a new List<Entry> everytime the grid decides it NeedDataSource is quite large?

 


     protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
            // Code...  
 
            switch (this.queryType)     
            {     
                case 1:    
                    this.RadGrid1.DataSource = new EntryDB().GetAllEntriesForUserAccount(...);    
                         break;     
                    case 2:     
                        this.RadGrid1.DataSource = new EntryDB().GetEntriesForSubject(...);     
                        break;     
                    case 3:     
                        this.RadGrid1.DataSource = new EntryDB().GetEntriesByLatestDate(...);     
                    default:     
                        this.RadGrid1.DataSource = null;     
                        break;     
                }     
        } 

Just need the same functionality as binding an object model to a Win32 app grid but I'd like to handle all the CRUD actions.

Thanks for your help.
Ian.

0
Todd Anglin
Top achievements
Rank 2
answered on 06 May 2009, 03:40 PM
Not sure where you saw the ObjectDataSource advice. It is not half bad for use in "advanced" scenarios where you want to bind your data declartively to a custom object model. When connected to the RadGrid, you benefit from "automatic" support for paging, sorting, filterting, etc.

That said, if I were brand new to ASP.NET, I don't know if I'd start there.

If you just want to use StoredProcs to do CRUD, the easiest place to start is the SqlDataSource control. It's not the best place to finish, but as a beginner with ASPNET, I'd "work-up" to the ObjectDataSource approach. You can learn how to use the SqlDataSource with StoredProcs here:


Let's start there and make sure you're comfortable with basic RadGrid CRUD and then learn from there. 

Hope that helps.

-Todd
0
Ian
Top achievements
Rank 1
answered on 06 May 2009, 09:59 PM
Thanks for the response Todd.

I am more than happy to "dive in deep" just need explanation on a some key points:

So, I've created an object source List<Entry> which is return from the GetEntriesForUserAccount()

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
{  
    this.RadGrid1.DataSource = new EntryDB().GetEntriesForUserAccount(1);  
}  
 

Works fine. The issue is that because the [_NeedDataSource] is called everytime you page next / previous, etc.

At least with the Session[""] storing the DataTable there were no further database connections / data re-selects, etc

Using the objects you have to connect to DB, Select data, create a collection, etc am I missing something?

Thanks for your patience,

Cheers
Ian.
0
Todd Anglin
Top achievements
Rank 2
answered on 07 May 2009, 01:09 AM
So, in this case, you're right. We're now talking about optimization stragies for caching your data in the UI layer so that you can reduce round trips to the DB. Session does work for this purpose, but is generally a good idea to avoid using Session if you can as it does not scale well at all (especially when used to hold large chuncks of data).

A better option for caching is to use the ASP.NET Cache mechanism. It is easier to scale and more suited for serving as a data caching layer. The other thing to remember is that an ASP.NET app- unlike a desktop app- lives right "next to" the DB server. That means there is very little latency (usually) between the web server and data server so there is less penalty for peforming operations against the DB (vs. a fat client).

You can read more on ASP.NET data caching stragies here:

The only thing I'll caution is adding too much complexity while you're getting started. If your goal is simply a functioning app that will serve as a rapid prototype (and your still learning the "way of the web"), it may be best to focus on function and not optimization  at this early stage. But if you're up to the challenge and want to jump in to the deep end, these articles should help.

-Todd
0
Ian
Top achievements
Rank 1
answered on 07 May 2009, 08:53 PM
Thanks for the advice Todd. I think I now have my data strategy sorted out...  UI + Cache Layer > Business > DAL. I am used to working with Client  (COM+ Business / DAL), etc so should be OK.

So all my "lookups" (generally less than 100 rows) will be cached and only the ID's within the main objects. Should be quick then?

Cheers
Ian.
Tags
Grid
Asked by
Ian
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Ian
Top achievements
Rank 1
Share this question
or