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

how can I get real value in datagrid column instead of 'System.Data.DataRowView'

3 Answers 348 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bashabi
Top achievements
Rank 1
Bashabi asked on 17 May 2016, 01:26 PM

This was the previous code in aspx file (done by previous developer)

 

  <radG:RadGrid ID="uxUsers" runat="server" RadControlsDir="~/RadControls/" AllowPaging="False"  HorizontalAlign="NotSet">        
        <MasterTableView AllowMultiColumnSorting="True" AllowSorting="True" ShowFooter="False" AutoGenerateColumns="False">           
            <Columns>
                <radG:GridBoundColumn DataField="name" HeaderText="Name" ReadOnly="True" UniqueName="name" />        
                <radG:GridBoundColumn DataField="email" HeaderText="Email" ReadOnly="True" UniqueName="email" /> 
               </Columns>
        </MasterTableView>
    </radG:RadGrid>

 

and the code behind it is 

  Private Sub BindEmployerUsers()
        uxUsers.DataSource = DB.GetData("SELECT eu.id, u.email, u.name + ' ' + u.surname AS name, CASE WHEN u.emailverified IS NULL THEN 'No' ELSE 'Yes' END AS emailverified, u.active FROM EmployerUser eu INNER JOIN [User] u ON eu.userid = u.id WHERE u.deleted = 0 AND  eu.employerid = " & Employer.ID)
        uxUsers.DataBind()
    End Sub

 

 

That was working fine. now i have added another column 

 

 <radG:RadGrid ID="uxUsers" runat="server" RadControlsDir="~/RadControls/" AllowPaging="False"  HorizontalAlign="NotSet">        
        <MasterTableView AllowMultiColumnSorting="True" AllowSorting="True" ShowFooter="False" AutoGenerateColumns="False">           
            <Columns>
                <radG:GridBoundColumn DataField="name" HeaderText="Name" ReadOnly="True" UniqueName="name" />        
                <radG:GridBoundColumn DataField="email" HeaderText="Email" ReadOnly="True" UniqueName="email" /> 
                <radG:GridBoundColumn DataField="primaruser" HeaderText="PrimarUser" ReadOnly="True" UniqueName="PrimarUser" /> 

              </Columns>
        </MasterTableView>
    </radG:RadGrid>

 

and the code behind this is 

 

    Private Sub BindEmployerUsers()
        uxUsers.DataSource = DB.GetData("SELECT  eu.id, u.email, u.name + ' ' + u.surname AS name,  CASE WHEN eu.id=e.primaryemployeruserid  THEN 'yes' ELSE 'No' END AS PrimaryUser, CASE WHEN u.emailverified IS NULL THEN 'No' ELSE 'Yes' END AS emailverified, u.active FROM Employer e INNER JOIN EmployerUser eu on e.id=eu.employerid INNER JOIN [User] u ON eu.userid = u.id WHERE u.deleted = 0 AND  eu.employerid = " & Employer.ID)
        uxUsers.DataBind()

    End Sub

 

but i get 'System.Data.DataRowView instead of real value.

 

how to fix this

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 19 May 2016, 02:11 PM
Hello Bashabi,

I have examined the code and noticed that the DataField property for the new column does not correspond to the field returned by the database query.

The DataField points to primaruser and the field in the Select statement is called PrimaryUser. Note that there is a 'y' missing in the first and the case is different. Make sure that the two strings match exactly and see how the behavior changes.

Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Alamelu Raj
Top achievements
Rank 1
answered on 15 Sep 2020, 12:14 AM

Hi team, I have a similar issue. I am creating columns in the code on Page_Load method with Postback check. When I load the page for the first time the grid is loaded with right data and the columns are also with the right name. But when i perform any action on the page, The columns disappear and I have system.Data.DataRowview. Could youplease lead me tothe right direction and guide me in this please.. 

Below is the code.

ASPX code : 

<telerik:RadGrid 
              ID="FileListGrid" 
              runat="server" 
              AllowSorting="true" 
              RenderMode="Classic" 
              GridLines="Both"  
              EnableAJAX="false"
              OnSortCommand ="FileListGrid_SortCommand"
              EnableViewState="true">
                 
              <MasterTableView 
                  AutoGenerateColumns ="false" 
                  DataKeyNames="Key" 
                  EnableViewState="true" 
                  EnableColumnsViewState="true" 
                  AllowSorting="true"                   
                  AllowNaturalSort="true"  >
         
            </MasterTableView> 
              <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true" AllowRowsDragDrop="True" >
                 <Selecting AllowRowSelect="True" EnableDragToSelectRows="true"/>
                 <Resizing  EnableRealTimeResize="True" ResizeGridOnColumnResize="True"  AllowColumnResize="True"></Resizing>
                  
        </ClientSettings> 
            </telerik:RadGrid>

NeedDataSource method:

  private void FileListGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            if (OnGridNeedDataSource != null)
            {
                FileListGridNeedDataSourceEventArgs gNeedSource = new FileListGridNeedDataSourceEventArgs(e.RebindReason.ToString());
                OnGridNeedDataSource(gNeedSource);
            }
        }

  protected void ContentManager_OnGridNeedDataSource(FileListGridNeedDataSourceEventArgs e)
        {
            ContentManager.FileListDataSource = GetAttachments();
        }

 

Page_load method:

 protected void Page_Load(object sender, EventArgs e)
{
            if (!Page.IsPostBack)
            {

                ContentManager.AddColumn(ATTACHMENTScope.KEY, false);
                ContentManager.AddColumn(ATTACHMENTScope.TITLE, false);
                ContentManager.AddColumn(ATTACHMENTScope.FILENAME, false); 
                ContentManager.AddColumn(FileListScope.SizeString, false, null, null, true, true);
                ContentManager.AddColumn(ATTACHMENTLISTScope.PAGECOUNT, false); 
                ContentManager.AddColumn(ATTACHMENTLISTScope.LASTMODIFIEDDATE, false); 
                ContentManager.AddColumn(FileListScope.FileDisabled, false, null, null, "ActionTemplate_Disabled", true, true);
                ContentManager.AddHiddenColumn(ATTACHMENTLISTScope.ID, false);
                ContentManager.AddTemplateColumn(FileListScope.DetailPageURL, false, null, null, null, null, System.Web.UI.WebControls.TextAlign.Right, null, "ActionTemplate_Url", false, false);
                ContentManager.FileListDataKeyField = ScopeHelper.GetDataFieldName(ATTACHMENTLISTScope.ID, false);
            }

}

AddColumn Method:

 

  public void AddColumn(string dataScope, bool tableQualified, Type dataType, int? width, bool? isVisible, string headingText,
            TextAlign? horizontalAlign, string clientTemplateId, string serverTemplateId, bool sortable, bool sortImageJustify)
        {

            GridBoundColumn column = new GridBoundColumn();
            if (dataScope != null)
            {
                CAColumnDataScope scope = new CAColumnDataScope(dataScope, tableQualified);
                column.DataField = scope.DataField;
                column.HeaderText = scope.HeadingText;
                column.UniqueName = scope.DataField;
            }


                FileListGrid.MasterTableView.Columns.Add(column);

}

 

Thanks

0
Doncho
Telerik team
answered on 17 Sep 2020, 04:21 PM

Hi Alamelu Raj,

I am afraid that the provided information is insufficient for us to reproduce the problem, hence to help with troubleshooting the case.

In general, the problem is most probably originated by an issue with the data binding. For example, the issue could be caused by some inconsistency in the names of the data source fields bound to the RadGrid and the DataFileds set to the Grid Columns.

Please check out the following resources and ensure the data is correctly bound to the RadGrid:

I have attached a very basic sample of RadGrid with dynamically defined columns, based on the sample in Dynamically Defining the Structure of a Statically-declared Grid section. Please try to modify the sample so that it replicates the described issue and send it back to us in a formal support ticket. It would also be helpful if you share an isolated runnable version of your project that will show us the problem so that we can debug it.

Kind regards,
Doncho
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Grid
Asked by
Bashabi
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Alamelu Raj
Top achievements
Rank 1
Doncho
Telerik team
Share this question
or