Solved

Telerik RadGrid Custom Edit Form With Date Picker

Posted on 2010-11-13
9
4,810 Views
Last Modified: 2012-06-27
I have a custom edit form in a Telerik RadGrid where I'm trying to get the dates to bind to the RadDatePicker controls. The problem is, when I bind the date to the control, it will not allow the form to show on insert because there is no date to bind on a new insert.  I have tried binding in the code behind and also in the main page using "Container is GridEditFormInsertItem" but I keep getting "Object reference not set to an instance of an object".

Any help would be appreciated.
<telerik:RadDatePicker ID="itemLastPurchaseRadDatePicker" runat="server" Width="150px"
        Culture="en-US" DateFormat="M/d/yyyy" DisplayDateFormat="M/d/yyyy" ShowPopupOnFocus="true"
        SelectedDate='<%# ((Container is GridEditFormInsertItem) ? false : Bind ("ItemVendorLastPriceDate"))  %>'>
</telerik:RadDatePicker>

Open in new window

I tried this in the code behind as a separate try to no avail.

 Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

        If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then
            Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
            Dim parentItem As GridDataItem = editFormItem.ParentItem
            Dim dateVendorLastPurchaseDate As RadDatePicker = CType(editFormItem.FindControl("itemLastPurchaseRadDatePicker"), RadDatePicker)
            Dim lastPurchaseDate As String = parentItem("ItemVendorLastPriceDate").Text
            If lastPurchaseDate <> "" Or lastPurchaseDate IsNot Nothing Then
                dateVendorLastPurchaseDate.SelectedDate = lastPurchaseDate
            End If
End Sub

Open in new window

0
Comment
Question by:vdevine15
  • 4
9 Comments
 
LVL 21

Accepted Solution

by:
masterpass earned 500 total points
Comment Utility
Hi,

I would first ask you to use the try catch block surrounding the code

or

use the breakpoints  to find which line of code is actually throwing up the error.

Once we find which line is actually causing the problem we will take it from there coz from what I see your code should work fine.
0
 
LVL 1

Author Comment

by:vdevine15
Comment Utility
I never got notified that there was a post on here, sorry...I'm checking this out now, I had moved onto something else because it was taking so long, will post back shortly.
0
 
LVL 1

Author Comment

by:vdevine15
Comment Utility
So on my ItemDataBound event for the insert, what when I use a Try/Catch is:

System.NullReferenceException: Object reference not set to an instance of an object. at DesktopModules_Inventory_inventoryMain.RadGrid1_ItemDataBound(Object sender, GridItemEventArgs e)
0
 
LVL 1

Author Comment

by:vdevine15
Comment Utility
I got it! I just added "And RadGrid1.MasterTableView.IsItemInserted = False" to my If statement on the ItemDataBound and it all worked like a charm! Thanks for the feedback and thanks to the moderators for helping me reclassify this!
0
 
LVL 1

Author Closing Comment

by:vdevine15
Comment Utility
You were the only one to respond, so you get the points anyway, thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to count occurrences of each item in an array.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now