I am having the problems while binding the UltraWebGrid with WebHierarchicalDataSource. I have two ObjectDataSource returns list object. I am not able to bind. I am geting the "Object reference not set to an instance of an object." error.
I tried with SqlDataSource its working fine. Is it WebHierarchicalDataSource supports only SqlDataSourc.
Please help out this.
Here my code:
<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" DataSourceID="WebHierarchicalDataSource1"> <Bands> <%-- BaseTableName and DataKeyField must both be specified to enable CRUD operations --%> <igtbl:UltraGridBand DataKeyField="PKTicketID"> <AddNewRow Visible="NotSet" View="NotSet"> </AddNewRow> <Columns> <igtbl:UltraGridColumn BaseColumnName="PKTicketID" DataType="System.Int64" IsBound="True" Key="PKTicketID"> <Header Caption="PKTicketID"> <RowLayoutColumnInfo OriginX="1" /> </Header> <Footer> <RowLayoutColumnInfo OriginX="1" /> </Footer> </igtbl:UltraGridColumn> </Columns> </igtbl:UltraGridBand> <igtbl:UltraGridBand DataKeyField="PKTicketID"> <AddNewRow Visible="NotSet" View="NotSet"> </AddNewRow> <Columns> <igtbl:UltraGridColumn BaseColumnName="PKTicketID" DataType="System.Int64" IsBound="True" Key="PKTicketID"> <Header Caption="PKTicketID"> <RowLayoutColumnInfo OriginX="1" /> </Header> <Footer> <RowLayoutColumnInfo OriginX="1" /> </Footer> </igtbl:UltraGridColumn> <igtbl:UltraGridColumn BaseColumnName="tickettitle" DataType="System.Int64" IsBound="True" Key="tickettitle"> <Header Caption="tickettitle"> <RowLayoutColumnInfo OriginX="1" /> </Header> <Footer> <RowLayoutColumnInfo OriginX="1" /> </Footer> </igtbl:UltraGridColumn> </Columns> </igtbl:UltraGridBand> </Bands> <DisplayLayout CompactRendering="False" AllowColSizingDefault="Free" AllowDeleteDefault="Yes" AutoGenerateColumns="false" AllowSortingDefault="Yes" AllowUpdateDefault="Yes" BorderCollapseDefault="Separate" HeaderClickActionDefault="SortMulti" Name="wgTicket" RowHeightDefault="20px" RowSelectorsDefault="No" SelectTypeRowDefault="Extended" SelectTypeCellDefault="Extended" Version="4.00" ViewType="Hierarchical" AllowColumnMovingDefault="OnClient" ScrollBarView="Horizontal" CellClickActionDefault="RowSelect" GridLinesDefault="None" HeaderTitleModeDefault="OnOverflow" TabDirection="BottomToTop" StationaryMargins="Header"> <RowStyleDefault CssClass="normal" Width="100%"> </RowStyleDefault> <RowAlternateStyleDefault CssClass="alternate"> </RowAlternateStyleDefault> <GroupByBox BoxStyle-BackColor="#FFFFC0" BoxStyle-HorizontalAlign="Center" BoxStyle-Height="10px"> </GroupByBox> <SelectedRowStyleDefault BackColor="LightGoldenrodYellow" ForeColor="Black" HorizontalAlign="Left" VerticalAlign="Middle"> </SelectedRowStyleDefault> <HeaderStyleDefault CssClass="iheader"> </HeaderStyleDefault> <FrameStyle Width="100%"> </FrameStyle> </DisplayLayout> </igtbl:UltraWebGrid>
<ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server"> <DataRelations> <ig:DataRelation ChildColumns="fkrelatedticketid" ChildDataViewID="SqlDataSource2_DefaultView" ParentColumns="Pkticketid" ParentDataViewID="SqlDataSource1_DefaultView" /> </DataRelations> <DataViews> <ig:DataView ID="SqlDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="odsTicket" /> <ig:DataView ID="SqlDataSource2_DefaultView" DataMember="DefaultView" DataSourceID="odsRelated" /> </DataViews> </ig:WebHierarchicalDataSource>
<asp:ObjectDataSource ID="odsTicket" runat="server" SelectMethod="GetAllPoolTicket" SortParameterName="SortExpression" TypeName="A1CRM.TicketBO"> </asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsRelated" runat="server" SelectMethod="GetAllRelatedTicketsInPopUp" TypeName="A1CRM.TicketBO" SortParameterName="SortExpression"> </asp:ObjectDataSource>
Hi,
it seems that the data relation is not correctly setup:
<ig:DataRelation ChildColumns="fkrelatedticketid" ChildDataViewID="SqlDataSource2_DefaultView" ParentColumns="Pkticketid" ParentDataViewID="SqlDataSource1_DefaultView" />
ParentColumns should be "PKTicketID" instead of "Pkticketid".
I hope that helps.
Thanks man its workig but it is not showing the "+" and child rows.
You are assigning -9999 to FKID of the root items - objTest.FKID = IIf(dr("FKID") Is DBNull.Value, -9999, dr("FKID"))
That way WHDS can not determine which are the root records, you'll have to leave them DBNull (or null) in order to use self-reference relation. If FKID is of type long you can change it to Nullable long (long?) and then assign null when the value is DBNull:
objTest.FKID = IIf(dr("FKID") Is DBNull.Value, null, dr("FKID"))
Hope that helps.
I tried with below conditions but it is not working.
objTest.FKID = IIf(dr("FKID") Is DBNull.Value, Nothing, dr("FKID")) objTest.FKID = IIf(dr("FKID") Is DBNull.Value, DBNull.Value, dr("FKID")) objTest.FKID = dr("FKID")
I think -99999 is not a problem. I have binded grid with same logic for different tables Ticket and Ticketdeail.But I am not able to bind same table with selfrelation.
binding code is here:
WHDS
<ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server"> <DataRelations> <ig:DataRelation ChildColumns="FKTicketId" ChildDataViewID="ObjectDataSource2_DefaultView" ParentColumns="PKTicketId" ParentDataViewID="ObjectDataSource1_DefaultView" /> </DataRelations> <DataViews> <ig:DataView ID="ObjectDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="ObjectDataSource1" /> <ig:DataView ID="ObjectDataSource2_DefaultView" DataMember="DefaultView" DataSourceID="ObjectDataSource2" /> </DataViews> </ig:WebHierarchicalDataSource>
ObjectDataSources:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetParentOrder" TypeName="A1CRM.TicketDB"></asp:ObjectDataSource> <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetChildOrders" TypeName="A1CRM.TicketDB"></asp:ObjectDataSource>
ObjectDataSource funtions:
Public Shared Function GetParentOrder() As List(Of TicketInfo) Dim dr As IDataReader = DataHelper.ExecuteReader(ConnectionString, CommandType.Text, "select Pkticketid,TicketTitle,FKRelatedTicketId,TicketDescription from ticket where PKTicketId IN(4910,4451,4697,4345)") Dim lstTickets As New System.Collections.Generic.List(Of TicketInfo) While dr.Read() Dim objTicket As New TicketInfo objTicket.PKTicketId = dr("PKTicketId") objTicket.TicketTitle = dr("TicketTitle") objTicket.TicketDescription = dr("TicketDescription") objTicket.FKRelatedTicketId = IIf(dr("FKRelatedTicketId") Is DBNull.Value, Null.NullInteger, dr("FKRelatedTicketId")) lstTickets.Add(objTicket) End While 'End If dr.Close() Return lstTickets End Function Public Shared Function GetChildOrders() As List(Of TicketDetailInfo) Dim dr As IDataReader = DataHelper.ExecuteReader(ConnectionString, CommandType.Text, "select Pkticketdetailid,FKTicketId ,Description from Ticketdetail where FKTicketId in(4910,4451,4697,4345)") Dim lstTicketDetail As New System.Collections.Generic.List(Of TicketDetailInfo) While dr.Read() Dim objTicketDetail As New TicketDetailInfo objTicketDetail.PKTicketDetailId = dr("Pkticketdetailid") objTicketDetail.FKTicketId = dr("FKTicketId") objTicketDetail.Description = dr("Description") lstTicketDetail.Add(objTicketDetail) End While 'End If dr.Close() Return lstTicketDetail End Function
Null.NullInteger is -99999
I have posted issue on Infragistics. Issue id:CAS-11530-1G9RQT.
I have attached the sample project also can you fix that sample project.
Hi, I have read all previous posts and i think i face the same issue with WebHierarchicalDataSource.
I have a self referencing data table in SqlServer 2005. I placed an SqlDataSource, a HierarchicalDataSource and an UltraWebMenu in an empty page. Everything works fine. The problem appears when i call this.DataBind() in the page load event. Then page childcontrols databinding is performed in a specific order. When the HierarchicalDataSource.DataBind() is called a null reference exception is thrown. If instead of this.DataBind(), when i call UltraWebMenu.DataBind() everything works fine again.
The reason this is an issue for me is because i use IronSpeed Designer for the project i currently work on. ISD internally calls Page.DataBind() in the Page.OnLoad event. Is there a workaround to this?
I am currently using 8.3.20083.2021 version of asp .net controls.
Thanks in advance, Kostas.
Thaks a lot for your suggestions. I think the second approach with CustomHierarchicalDataSource will do the job.
Hi Kostas,
I'm not familiar with the IronSpeed Designer, is it possible to configure it not to call Page.DataBind()?
If that's not an option then I can suggest you two workarounds:
1. override Page.DataBind:
public override void DataBind() { try { base.DataBind(); } catch (NullReferenceException) { } }
2. Derive from WebHierarchicalDataSource and override DataBind to do nothing:
public class CustomHierarchicalDataSource : WebHierarchicalDataSource { public override void DataBind() { } }
Then use CustomHierarchicalDataSource instead of WebHierarchicalDataSource.
Hope that helps for now. We are going to fix that in future versions and hotfixes of the control.