Custom Control - RadGrid - DataBinder.Eval throwing null err

Posted by Community Admin on 04-Aug-2018 21:31

Custom Control - RadGrid - DataBinder.Eval throwing null error - need help

All Replies

Posted by Community Admin on 01-Mar-2012 00:00

Hello,
So I have an issue where I am trying to get the key field value from a RadGrid in to a label using Eval and I get Value Cannot Be Null. If I put a value instead, the grid works fine. Can someone see why the Eval of Emp# does not work?
Here is the line from the entire ASPX.

<asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# DataBinder.Eval(Container.DataItem,"Emp#") %>' Visible="true" runat="server" />
 
And I tried:
 
<asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("Emp#") %>' Visible="true" runat="server" />


Here is the entire ASPX.

<%@ Control Language="C#" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sitefinity" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
 
    <div class="oneColumn" style="position:relative;">
            <h3>YRMC Employee Photo Directory</h3>           
    </div>
 
        <div class="twoColumn" style="float:left; width:45%;">
                    <asp:Label ID="lblCampus" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="Medium"
                        ForeColor="#880000" Text="Campus/Location" Width="172px"></asp:Label><br />
                    <asp:DropDownList ID="ddLocation" runat="server" AutoPostBack="True" Width="270px">                       
                    </asp:DropDownList>
                          <br />
                <br />
                    <asp:Label ID="lblDepartment" runat="server" Font-Names="Arial" Text="Department"
                        Width="174px" Font-Bold="True" Font-Size="Medium" ForeColor="#880000"></asp:Label><br />
                    <asp:DropDownList ID="ddDepartment" runat="server"
                        Width="270px" AutoPostBack="True" ToolTip="Select a Department" >                                                             
                        </asp:DropDownList><br />
                <br />
                <b>*Disclaimer: Employee photographs should be used for business purposes only.</b>
         <br /><br />
         </div>
          
         <div class="twoColumn" style="float:right; width:45%;" >
                 
                        <asp:Label ID="lblEmpName" runat="server" Font-Names="Arial" Text="Search by Employee Name"
                            Width="294px" Font-Bold="True" Font-Size="Medium" ForeColor="#880000"></asp:Label><br />
                        <asp:Label ID="lblSearchName2" runat="server" Font-Names="Arial" Text=" (Search for a name or any part of a name.)"
                            Width="294px"></asp:Label><br />
                        <asp:TextBox ID="txtSearchName" runat="server" Width="270px" ToolTip="Searches for a name or any part of a name."></asp:TextBox>
                        <asp:Button ID="btnSearchName" runat="server" Font-Bold="True" ForeColor="Maroon" Text="Search!" Width="105px" />
                        <br /><br />
                        <b>Note:</b> Please contact HR x 5795 with any questions.
                         Please ask employees without photos to contact HR to
                        have a picture taken. Photos of future employees are not available prior to their hire date.<br />                       
         </div>
                   
         <div style="clear:both" />
              
         <input type="button" onclick="history.go(0)" value="Reset List" style="color:Maroon; font-weight:bold; width:105px" />
         <br />        
         
        <div style="width:100%;height:600px;overflow-y:auto;overflow-x:hidden;padding:5px 5px 5px 5px; border: thin solid silver;">        
                 
            <asp:Label ID="lblSort" runat="server" Font-Bold="True" Font-Size="Smaller" ForeColor="Maroon"
                Text="You may sort on any category by clicking on any column heading." Font-Italic="True" Width="440px"></asp:Label>
            <br />
 
                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="rgEmployees">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="rgEmployees" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
                </telerik:RadAjaxManager>
                 
 
                <telerik:RadGrid id="rgEmployees" runat="server" allowpaging="True" AllowSorting="true" PageSize="20" DataSourceID="SqlSource1" OnPreRender="RadGrid1_PreRender"
                        AutoGenerateColumns="False" AllowFilteringByColumn="false" Skin="Outlook" OnItemCreated="RadGrid1_ItemCreated" OnItemCommand="RadGrid1_ItemCommand" >
                    <MasterTableView DataSourceID="SqlSource1" PageSize="20" DataKeyNames="Emp#">
                        <NestedViewTemplate>
                            <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="true">
                                <telerik:RadTabStrip runat="server" ID="TabStrip1" MultiPageID="Multipage1" SelectedIndex="0">
                                    <Tabs>
                                        <telerik:RadTab runat="server" Text="Details" Selected="true" PageViewID="PageView1"></telerik:RadTab>
                                    </Tabs>
                                </telerik:RadTabStrip>
                                <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false">
                                    <telerik:RadPageView runat="server" ID="PageView1">
                                        <asp:Label ID="Label1" Font-Bold="true" Font-Italic="true" Text='<%# DataBinder.Eval(Container.DataItem,"Emp#") %>' Visible="true" runat="server" />
                                        <div class="contactWrap">
                                            <table cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td>
                                                        <asp:FormView ID="DetailsView1" runat="server" DataSourceID="SqlSource2">
                                                            <ItemTemplate>
                                                                <hr />
                                                                <h1><%# Eval("FullName") %></h1>
                                                                <table border="0">
                                                                    <tr>
                                                                        <td class="EmployeePropertyLabel">Job Title</td>
                                                                        <td class="EmployeePropertyValue"><%# Eval("JobTitle") %></td>
                                                                        <td rowspan="5"><img src='file://\\apidata\Image\<%# Eval("Photo") %>' alt="Employee Photo" /></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="EmployeePropertyLabel">Department Name</td>
                                                                        <td class="EmployeePropertyValue"><%# Eval("DeptName") %></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="EmployeePropertyLabel">Campus</td>
                                                                        <td class="EmployeePropertyValue"><%# Eval("Campus") %></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="EmployeePropertyLabel">Shift</td>
                                                                        <td class="EmployeePropertyValue"><%# Eval("Shift") %></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td class="EmployeePropertyLabel">Hire Date</td>
                                                                        <td class="EmployeePropertyValue"><%# Eval("HireDate") %></td>
                                                                    </tr>
                                                                </table>
                                                                <hr />
                                                            </ItemTemplate>
                                                        </asp:FormView>
                                                        <asp:SqlDataSource ID="SqlSource2" runat="server" ConnectionString="Data Source=SomeTable;Initial Catalog=;User ID=;Password="
                                                            SelectCommand="SELECT * FROM dbo.wwwEmployeePhotos WHERE (Emp# = @Emp#)" ProviderName="System.Data.SqlClient">
                                                            <SelectParameters>
                                                                <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="Emp#" />
                                                            </SelectParameters>
                                                        </asp:SqlDataSource>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </telerik:RadPageView>
                                </telerik:RadMultiPage>
                            </asp:Panel>
                        </NestedViewTemplate>
                        <Columns>
                            <telerik:GridBoundColumn UniqueName="Emp#" DataField="Emp#" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="LastName" HeaderText="Last Name" SortExpression="LastName" DataField="LastName"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="First Name" SortExpression="FirstName" DataField="FirstName"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="DeptName" HeaderText="Department Name" SortExpression="DeptName" DataField="DeptName"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="HireDate" HeaderText="Last Hire Date" SortExpression="HireDate" DataField="HireDate"></telerik:GridBoundColumn>
                        </Columns>
                        <RowIndicatorColumn Visible="False">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                    </MasterTableView>
                </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlSource1" runat="server" ConnectionString="Data Source=SomeDB;Initial Catalog=;User ID=;Password="
                SelectCommand="SELECT DISTINCT FullName, FirstName, LastName, Campus, Emp#, DeptName, convert(varchar,HireDate,101) as HireDate FROM [wwwEmployeePhotos] WHERE (UPPER(Campus) LIKE '%' + UPPER(@searchCampus_string) + '%') AND (UPPER(DeptName) LIKE UPPER(@searchDepartment_string)) AND (UPPER(FullName) LIKE '%' + UPPER(@searchName_string) + '%') ORDER by FullName"
                ProviderName="System.Data.SqlClient">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ddLocation" DefaultValue="%" Name="searchCampus_string"
                        PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="ddDepartment" DefaultValue="%" Name="searchDepartment_string"
                        PropertyName="SelectedValue" />
                    <asp:ControlParameter ControlID="txtSearchName" DefaultValue="%" Name="searchName_string"
                        PropertyName="Text" />
                </SelectParameters>
        </asp:SqlDataSource>
             
             
        </div>

Posted by Community Admin on 02-Mar-2012 00:00

This does work, there was a Null. Ugh.

This thread is closed