Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Saturday, May 22, 2010
( Telerik )

Whilst using Telerik’s CMS SiteFinity (see other blog posts) I started to use their RadGrid.

So why use these third party components? According to Telerik:

“…help you build high-quality, professional line of business web applications. …maximizing productivity and creating rich, SEO-friendly, high-performance Enterprise web applications.”

Their Grid is USD999, and has combined questions in their forums of 100,000 on the grid (over asp.net and asp.net ajax).  It is their most popular control.

So what can it do?  Here is an example showing LinqToSQL as the ORM

 http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/linqdatasource/defaultcs.aspx

http://tv.telerik.com/radtips/episode/using-the-linqdatasource-in-your-radgrid

image

Got some issues with errors and internal server errors on my shared host. 

<customErrors mode="off"/>

 

Theme: Web Blue

image

Drop Down:  link to CountryID, a new data Source

image

Data Editing:   AllowAutomaticDeletes, Inserts, Updates

Paging:  PageSize = 20

MasterTableView, EditMode, InPlace

image

and can edit the country as well with a drop down.

Date – used {0:d} to only get the date

Cost:

image

image

How to Do a Drop Down based on a filter

Using a RadComboBox:

Chosen the datasource, and DataText field = name  and DataValueField  = countryid

image

AutoPostBack = true

Put a conditional on the original linked data source.

image

It all works as expected.

Uploading to live

Project is now:  TestRadGridTelerik3… uploading to radgrid2 on server

Add a Record

image

Mastertable view, CommandItemDisplay = top

Manually Controlling The Grid

I want to be able to insert into the grid, based on my logged in user.  So have to manually hook into the events

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/programaticlinqupdates/defaultcs.aspx

http://www.telerik.com/help/aspnet-ajax/grdlinqtosqlmanualcrudoperations.html

Using TestRadGridTelerik3 project, addSmart.aspx

<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" AllowPaging="True"
        OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
        OnItemCreated="RadGrid1_ItemCreated" OnDeleteCommand="RadGrid1_DeleteCommand"
        OnInsertCommand="RadGrid1_InsertCommand" GridLines="None">

<telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />

image

Very nice goodness baked in for delete

protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
{
var raceId = (Guid) ((GridDataItem) e.Item).GetDataKeyValue("RaceID");

//retrive entity form the Db
var race = DbContext.races.Where(n => n.raceid == raceId).FirstOrDefault();
if (race != null)
{
//add the category for deletion
DbContext.races.DeleteOnSubmit(race);
try
{
//submit chanages to Db
DbContext.SubmitChanges();
}
catch (Exception)
{
ShowErrorMessage();
}
}
}

There is a double click event on the row.. which goes into edit mode.  This is wired up in JavaScript.

Getting nice js numeric error checking on the input for money and distance.

image

 

Have got delete working

**Update doesn’t work

**Insert doesn’t work

**The error message don’t show up properly.

**changed teh db structure locally for race to allow nulls for categoryid… maybe vioates an FK constraint.??  see profiler?

Problem with Updating

Found that I couldn’t understand what was happening.  So went back to the example code by Telerik on: http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/programaticlinqupdates/defaultcs.aspx

Ripped out the code, made a simple LinqToSQL class against 1 table only (Products).  Got it working locally:

image

this is called RadGrid4Telerik.

Next step is to get my example of races working with 1 table only (just like this).  Problem with taking this live is that Northwind is quite a large db and complex and I’ve got average hosting!  Also very good to bring back to basics.

All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview