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

[Solved] GridTableView problem

5 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 10 Apr 2008, 02:17 PM
Hi all,


I have radGrid on my web page.  I now want to display a child GridTableView which will display some detail information.  My radGrid is named Illustration and my GridTableView is named IllustrationDetail.  I want to use the IllustrationID from my radGrid to fetch the rows from my database to populate IllustrationDetail.  I do not know how to get the value of IllustrationID from my radGrid.  I was trying to use "FindControl" but it gives me an error.  Here is my code:


Protected

Sub rgIllustration_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgIllustration.DetailTableDataBind

Dim dataItem As Telerik.Web.UI.GridDataItem = CType(e.DetailTableView.ParentItem, Telerik.Web.UI.GridDataItem)

Dim IllustrationID As String = dataItem.FindControl("IllustrationID").ToString()

e.DetailTableView.DataSource = LifePolicy.GetLifePolicyIllustrationDetailList(IllustrationID)

End Sub

So how I can get the value of IllustrationID from the selected row of my RadGrid?

Thanks,
Bob

5 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 14 Apr 2008, 12:05 PM
Hi Bob,

You can add the IllustrationID field to the DataKeyNames collection of the master table and retrieve its value using the GetDataKeyValue(fieldName) method as shown in this demo:

http://www.telerik.com/DEMOS/ASPNET/Prometheus-futures/Grid/Examples/Programming/DetailTableDataBind/DefaultVB.aspx (see the DetailTableDataBind handler)

Another option is to use declarative parent table relations.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 14 Apr 2008, 08:38 PM
Stephen,

I changed my code and html to use the DataKeyNames collection.  I have used this several times before on other pages.  But I cannot get it to work here.  The only difference is that now my radgrid is on a user control.  The other times I used this technique it was always on web pages and worked perfectly.  Is there an issue with this technique on a user control?  Here is the code:

Protected

Sub rgIllustration_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgIllustration.NeedDataSource

If Not e.IsFromDetailTable Then

rgIllustration.DataSource = LifePolicy.GetLifePolicyIllustrationList(

CInt(Request.QueryString("LifePolicyID")))

End If

End Sub

Protected Sub rgIllustration_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rgIllustration.DetailTableDataBind

Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)

Dim IllustrationID As String = dataItem.GetDataKeyValue("IllustrationID").ToString()

e.DetailTableView.DataSource = LifePolicy.GetLifePolicyIllustrationDetailList(

CInt(IllustrationID))

End Sub




Here is the line in error:

Dim IllustrationID As String = dataItem.GetDataKeyValue("IllustrationID").ToString()

The error is:

Object reference not set to an instance of an object.

So what am I doing wrong?

Thanks,
Bob

0
Sebastian
Telerik team
answered on 15 Apr 2008, 06:21 AM
Hi Bob,

Can you please double-check that you added the IllustrationID field to the DataKeyNames collection of the master table? If the problem seems to be elsewhere, I suggest you paste your grid declaration along with the relevant code-behind logic in this forum post. I will examine it in detail and will get back to you with more info on the matter.

Regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bob
Top achievements
Rank 1
answered on 15 Apr 2008, 04:10 PM
Hi Stephen,

Here is the HTML in my user control, Illustration.ascx, which contains the RadGrid:

<

telerik:RadGrid ID="rgIllustration"

runat="server"

AutoGenerateColumns="False"

SkinID="GridSkin"

GridLines="None"

AllowFilteringByColumn="True"

AllowPaging="true"

AllowSorting="true"

PagerStyle-Mode="NextPrevAndNumeric"

PageSize="20"

GroupingSettings-CaseSensitive="false">

<MasterTableView GridLines="both"

Name="Master"

Width="100%"

CommandItemDisplay="Top"

DataKeyNames="IllustrationID"

EditFormSettings-EditFormType="WebUserControl">

I already posted the vb.net code in my last post.  And like I said in my last post, the vb.net bombs on this line:

Dim IllustrationID As String = dataItem.GetDataKeyValue("IllustrationID").ToString()

In debug mode, the value for dataItem.GetDataKeyValue("IllustrationID").ToString()
 is Nothing.

I have used this same technique several times with no problems.  The only difference is that now I am trying this on a user control instead of a web form.

Thanks,
Bob


0
Sebastian
Telerik team
answered on 18 Apr 2008, 01:56 PM
Hello Bob,

This is indeed strange as your syntax seems correct and I cannot say for certain what might cause the erroneous behavior. Does using DataKeyValues instead of the GetDataKeyValue(keyField) method makes a difference?
If the problem persists, I suggest you isolate a stripped working version of your project and send it attached to a formal support ticket. I will debug the example locally and will get back to you with more info on the subject.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Bob
Top achievements
Rank 1
Share this question
or