Change telerik radgrid column name runtime
  • I have this query below
    DECLARE
    @colsComplaint AS NVARCHAR(MAX),
    @colsDate AS NVARCHAR(MAX),
    @ColumnAliases nvarchar(max),


    @PivotSQL AS NVARCHAR(MAX)

    -- Build column/alias string
    Select
        @colsComplaint = ISNULL(@colsComplaint + ', ', '') +
                QUOTENAME(Combined + '_Compliant'),
        @colsDate = ISNULL(@colsDate + ', ', '') +
                QUOTENAME(Combined + '_Date'),
        @ColumnAliases = ISNULL(@ColumnAliases + ', ', '') +
                 'Max(' + QUOTENAME(Combined + '_Date') + ') As ' + QUOTENAME(Combined + '_Date') + ', ' +           
                'Max(' + QUOTENAME(Combined + '_Compliant') + ') As ' + QUOTENAME(Combined + '_Compliant')
    From vCervidInspections
    group by combined;
    -- Plug in the column/alias strings
    Set @PivotSQL = 'Select LastName,HcStatus,' + @ColumnAliases + CHAR(10) +
        'From (Select LastName,HcStatus,Combined + ''_Compliant'' As Combined_Compliant,
               Combined + ''_Date'' As Combined_Date, Compliant, InspectionDate
               From vCervidInspections
               --group by LastName,HcStatus
               ) As MainSub
        Pivot
        (
        MAX(Compliant) For Combined_Compliant In (' + @colsComplaint + ')
        ) As Pvt1
        Pivot
        (
        MIN(InspectionDate) For Combined_Date In (' + @colsDate + ')
        ) As Pvt2
        Group By LastName,HcStatus;';
     
    Exec sp_executesql @PivotSQL;
     
    The output is on this url below:
    http://imageshack.com/a/img34/424/bt4q.png

    Now i want to replace  all _Date to ' ' and every column that contain _COMPLIANT to become COMPLIANT either on the query or in c# code code.
    So for example :
    S005_DATE will become S2005 and S2005_COMPLIANT will become COMPLIANT
    S2007_DATE will become S2007 and S2005_COMPLIANT will become COMPLIANT.

    Thank You
  • 4 Comments sorted by
  • Vote Up1Vote Down ithackerithacker
    117.50 Karma Accepted Answer
    i think its your query side issue
    change your this line

      @ColumnAliases = ISNULL(@ColumnAliases + ', ', '') +
                 'Max(' + QUOTENAME(Combined + '_Date') + ') As ' + QUOTENAME(Combined + '_Date') + ', ' +          
                'Max(' + QUOTENAME(Combined + '_Compliant') + ') As ' + QUOTENAME(Combined + '_Compliant')

    to this one

      @ColumnAliases = ISNULL(@ColumnAliases + ', ', '') +
                 'Max(' + QUOTENAME(Combined + '_Date') + ') As ' + QUOTENAME(Combined + '_Date') + ', ' +          
                'Max(' + QUOTENAME(Combined + '_Compliant') + ') As ' + QUOTENAME('aCompliant')
  • kindly share your front end code how you filling grid.
  • Hello @ithacker i attached the front end code
    <%@ Page Title="" Language="C#" MasterPageFile="~/Reports/Report.Master" AutoEventWireup="true" CodeBehind="InspectionCompliances.aspx.cs" Inherits="AHP.Reports.InspectionCompliances" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <div id="cont" style="margin-left:-520px">
        <h3>INSPECTIONS AND COMPLIANCES</h3>
        <hr />
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" 
            CellSpacing="0" DataSourceID="SqlDataSource1" GridLines="None" PageSize="25">
            <MasterTableView DataSourceID="SqlDataSource1">
            </MasterTableView>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AHP2ConnectionString %>" 
            SelectCommand="usp_GenerateInspectionCompliances" 
            SelectCommandType="StoredProcedure"></asp:SqlDataSource>
           </div>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ExtraScripts" runat="server">
    </asp:Content>


Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Optimum Creative