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>
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
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.
Yes if I bind ObjectDataSource3 to UltraWebGrid2 grid is binding. If I bind with SqlDataSource it is coming.
Here my page code.
Grid:
<igtbl:UltraWebGrid ID="UltraWebGrid2" runat="server" DataSourceID="ObjectDataSource3" Height="115px" Width="961px" DataKeyField="PKID">
</igtbl:UltraWebGrid>
ObjectDataSource3 :
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="GetAllTest" TypeName="TestDB"></asp:ObjectDataSource>
GetAllTest function:
Public Shared Function GetAllTest() As List(Of TestInfo) Dim connectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ToString Dim queryString As String = _ " SELECT PKID,FKID,Name,Description from Test" Dim lstTest As New System.Collections.Generic.List(Of TestInfo) Using connection As New SqlConnection(connectionString) Dim command As SqlCommand = connection.CreateCommand() command.CommandText = queryString Try connection.Open() Dim dr As SqlDataReader = _ command.ExecuteReader() While dr.Read() Dim objTest As New TestInfo objTest.PKID = dr("PKID") objTest.FKID = IIf(dr("FKID") Is DBNull.Value, -9999, dr("FKID")) objTest.Name = dr("Name") objTest.Description = dr("Description") lstTest.Add(objTest) End While dr.Close() Catch ex As Exception End Try End Using Return lstTest
End Function
This SqlDataSource
<ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource3" runat="server"> <DataRelations> <ig:DataRelation ChildColumns="FKID" ChildDataViewID="SqlDataSource1_DefaultView" ParentColumns="PkID" ParentDataViewID="SqlDataSource1_DefaultView" /> </DataRelations> <DataViews> <ig:DataView ID="SqlDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="SqlDataSource1" /> </DataViews> </ig:WebHierarchicalDataSource> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM [Test]"></asp:SqlDataSource>
Are you sure that your object data source is correctly setup, does the UltraGrid display any data if bound directly to ObjectDataSource3?
This is another grid I am making self relation. when I run this I am getting No Data To Display message. I have created a test table in northwid for sample project and my datasource query is "SELECT PKID,FKID,Name,Description from Test".
Can you please check this sample code and let me now my mistakes.
<igtbl:UltraWebGrid ID="UltraWebGrid2" runat="server" DataSourceID="WebHierarchicalDataSource2" Height="115px" Width="961px" DataKeyField="PKID"> <Bands> <igtbl:UltraGridBand AddButtonCaption="ObjectDataSource3_DefaultView" BaseTableName="ObjectDataSource3_DefaultView" Key="ObjectDataSource3_DefaultView"> <Columns> <igtbl:UltraGridColumn BaseColumnName="PKID" DataType="System.Int32" IsBound="True" Key="PKID"> <Header Caption="PKID"> </Header> </igtbl:UltraGridColumn> <igtbl:UltraGridColumn Key="FKID" IsBound="True" BaseColumnName="FKID"> <Header Caption="FKID"> <RowLayoutColumnInfo OriginX="1"></RowLayoutColumnInfo> </Header> <Footer> <RowLayoutColumnInfo OriginX="1"></RowLayoutColumnInfo> </Footer> </igtbl:UltraGridColumn> <igtbl:UltraGridColumn Key="Name" IsBound="True" BaseColumnName="Name"> <Header Caption="Name"> <RowLayoutColumnInfo OriginX="2"></RowLayoutColumnInfo> </Header> <Footer> <RowLayoutColumnInfo OriginX="2"></RowLayoutColumnInfo> </Footer> </igtbl:UltraGridColumn> <igtbl:UltraGridColumn Key="Description" IsBound="True" BaseColumnName="Description"> <Header Caption="Description"> <RowLayoutColumnInfo OriginX="3"></RowLayoutColumnInfo> </Header> <Footer> <RowLayoutColumnInfo OriginX="3"></RowLayoutColumnInfo> </Footer> </igtbl:UltraGridColumn> </Columns> <AddNewRow View="NotSet" Visible="NotSet"> </AddNewRow> </igtbl:UltraGridBand> <igtbl:UltraGridBand DataKeyField="FKID" Key="FKID"> <AddNewRow Visible="NotSet" View="NotSet"> </AddNewRow> <Columns> <igtbl:UltraGridColumn BaseColumnName="FKID" DataType="System.Int32" IsBound="True" Key="FKID"> <Header Caption="OrderID"> </Header> </igtbl:UltraGridColumn> <igtbl:UltraGridColumn BaseColumnName="PKID" DataType="System.Int32" IsBound="True" Key="PKID"> <Header Caption="PKID"> <RowLayoutColumnInfo OriginX="2" /> </Header> <Footer> <RowLayoutColumnInfo OriginX="2" /> </Footer> </igtbl:UltraGridColumn> <igtbl:UltraGridColumn BaseColumnName="Description" DataType="System.Int16" IsBound="True" Key="Description"> <Header Caption="Description"> <RowLayoutColumnInfo OriginX="2" /> </Header> <Footer> <RowLayoutColumnInfo OriginX="2" /> </Footer> </igtbl:UltraGridColumn> </Columns> </igtbl:UltraGridBand> </Bands> <DisplayLayout AllowColSizingDefault="Free" AllowColumnMovingDefault="OnServer" AllowDeleteDefault="Yes" AutoGenerateColumns="false" AllowSortingDefault="OnClient" AllowUpdateDefault="Yes" BorderCollapseDefault="Separate" HeaderClickActionDefault="SortMulti" Name="UltraWebGrid1" RowHeightDefault="20px" RowSelectorsDefault="No" SelectTypeRowDefault="Extended" StationaryMargins="Header" StationaryMarginsOutlookGroupBy="True" TableLayout="Fixed" Version="4.00" ViewType="OutlookGroupBy"> <FrameStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt" Height="115px" Width="961px"> </FrameStyle> <Pager MinimumPagesForDisplay="2"> <PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </PagerStyle> </Pager> <EditCellStyleDefault BorderStyle="None" BorderWidth="0px"> </EditCellStyleDefault> <FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </FooterStyleDefault> <HeaderStyleDefault BackColor="LightGray" BorderStyle="Solid" HorizontalAlign="Left"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </HeaderStyleDefault> <RowStyleDefault BackColor="Window" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt"> <Padding Left="3px" /> <BorderDetails ColorLeft="Window" ColorTop="Window" /> </RowStyleDefault> <GroupByRowStyleDefault BackColor="Control" BorderColor="Window"> </GroupByRowStyleDefault> <GroupByBox> <BoxStyle BackColor="ActiveBorder" BorderColor="Window"> </BoxStyle> </GroupByBox> <AddNewBox Hidden="False"> <BoxStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </BoxStyle> </AddNewBox> <ActivationObject BorderColor="" BorderWidth=""> </ActivationObject> <FilterOptionsDefault> <FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px" Height="300px" Width="200px"> <Padding Left="2px" /> </FilterDropDownStyle> <FilterHighlightRowStyle BackColor="#151C55" ForeColor="White"> </FilterHighlightRowStyle> <FilterOperandDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px"> <Padding Left="2px" /> </FilterOperandDropDownStyle> </FilterOptionsDefault> </DisplayLayout> </igtbl:UltraWebGrid> <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="GetAllTest" TypeName="TestDB"></asp:ObjectDataSource> <br /> <ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource2" runat="server"> <DataRelations> <ig:DataRelation ChildColumns="FKID" ChildDataViewID="ObjectDataSource3_DefaultView" ParentColumns="PKID" ParentDataViewID="ObjectDataSource3_DefaultView" /> </DataRelations> <DataViews> <ig:DataView ID="ObjectDataSource3_DefaultView" DataMember="DefaultView" DataSourceID="ObjectDataSource3" /> </DataViews> </ig:WebHierarchicalDataSource>