Telerik Forums
UI for ASP.NET AJAX Forum
3 answers
35 views
Exception was thrown at line 626, column 23 in http://aspnet-scripts.telerikstatic.com/ajaxz/2013.3.1324/ComboBox/RadComboBoxScripts.js0x800a138f - JavaScript runtime error: Unable to get property 'createRange' of undefined or null reference
Peter Filipov
Telerik team
 answered on 11 Feb 2014
3 answers
100 views
Are there any ready-made examples of how I could bind RadAutoComplete to a SharePoint list via web services? 
Keith
Top achievements
Rank 1
 answered on 11 Feb 2014
2 answers
99 views
Hi All. How Can i get Tile Badge Value using javascript.???
Amigo
Top achievements
Rank 1
 answered on 11 Feb 2014
5 answers
438 views
i Have a radgrid (rad1)  inside a FormTemplate of another RadGrid (rad2).

If i update a row in (rad1) while (rad2) is in editmode, the (rad1) UpdateCommand get only empty values. ,


how i can do it????

UPDATE: i found that this happen because NeedDataSource of (rad1) is beign called before UpdateCommand,
this doesnt happens if the radgrid is not inside of another RadGrid.


<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AutoGenerateColumns="False" 
        Skin="WebBlue" OnInsertCommand="RadGrid1_InsertCommand" OnItemDataBound="RadGrid1_ItemDataBound">  
        <MasterTableView CommandItemDisplay="Top" EditMode="PopUp" CommandItemSettings-AddNewRecordText="Agregar Estándar" 
            CommandItemSettings-RefreshText="">  
            <RowIndicatorColumn>  
                <HeaderStyle Width="20px"></HeaderStyle>  
            </RowIndicatorColumn>  
            <ExpandCollapseColumn>  
                <HeaderStyle Width="20px"></HeaderStyle>  
            </ExpandCollapseColumn>  
            <Columns>  
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" Display="false" />  
                <telerik:GridBoundColumn DataField="Ciudad" UniqueName="Ciudad" HeaderText="Ciudad" />  
                <telerik:GridBoundColumn DataField="Aeropuerto" UniqueName="Aeropuerto" HeaderText="Aeropuerto" />  
                <telerik:GridBoundColumn DataField="Proceso" UniqueName="Proceso" HeaderText="Proceso" />  
            </Columns>  
            <EditFormSettings EditFormType="Template" PopUpSettings-Modal="true" PopUpSettings-Width="500px" 
                CaptionFormatString="Insertar nueva propiedad">  
                <FormTemplate>  
                    <center>  
                        <table style="text-align: left">  
                            <tr>  
                                <td>  
                                    <br />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    <asp:Literal ID="Literal4" runat="server" Text="Aerolinea" />  
                                </td>  
                                <td>  
                                    <telerik:RadComboBox ID="RadComboBoxAeronave" runat="server" DataTextField="Aeronave" 
                                        DataValueField="ID" Skin="WebBlue" DataSourceID="ObjectDataSourceAeronave" OnClientSelectedIndexChanged="LoadValores" />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    <asp:Literal ID="Literal3" runat="server" Text="Modelo Avión" />  
                                </td>  
                                <td>  
                                    <telerik:RadComboBox ID="RadComboBoxTipoAvion" runat="server" Skin="WebBlue" DataTextField="DE_NAVE" 
                                        DataValueField="ID_NAVE" OnItemsRequested="RadComboBoxTipoAvion_ItemsRequested" 
                                        OnClientItemsRequested="ItemsLoaded" EmptyMessage="Seleccione Aerolinea..." />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    <asp:Literal ID="Literal2" runat="server" Text="Aeropuerto" />  
                                </td>  
                                <td>  
                                    <telerik:RadComboBox ID="RadComboBoxAeropuerto" runat="server" DataTextField="Aeropuerto" 
                                        DataValueField="ID" Skin="WebBlue" DataSourceID="ObjectDataSourceAeropuerto" />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    <asp:Literal ID="Literal1" runat="server" Text="Proceso" />  
                                </td>  
                                <td>  
                                    <telerik:RadComboBox ID="RadComboBoxProcesos" runat="server" DataSourceID="EntityDataSourceProcesos" 
                                        DataTextField="DE_PROC" DataValueField="ID_PROC" Skin="WebBlue" />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    &nbsp;  
                                </td>  
                                <td>  
                                    <asp:CheckBox Text="Activo" ID="CheckBox1" runat="server" Checked="true" />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    <br />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td colspan="2">  
                                    <telerik:RadGrid ID="RadGridStandards" AutoGenerateColumns="false" Skin="WebBlue" 
                                        OnNeedDataSource="RadGridStandards_NeedDataSource" GridLines="None" runat="server" 
                                        AllowMultiRowSelection="True" AllowMultiRowEdit="True"   
                                        OnUpdateCommand="RadGridStandards_UpdateCommand" OnItemDataBound="RadGridStandards_ItemDataBound" 
                                        AllowAutomaticUpdates="false">  
                                        <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false" EditFormSettings-EditFormType="AutoGenerated" 
                                            EditMode="InPlace" DataKeyNames="ID">  
                                            <CommandItemTemplate>  
                                                <div style="padding: 5px 5px;">  
                                                    <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGridStandards.EditIndexes.Count == 0 %>'>Editar</asp:LinkButton>&nbsp;&nbsp;  
                                                    <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGridStandards.EditIndexes.Count > 0 %>'>Actualizar</asp:LinkButton>&nbsp;&nbsp;  
                                                    <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGridStandards.EditIndexes.Count > 0 || RadGridStandards.MasterTableView.IsItemInserted %>'>Cancelar</asp:LinkButton>  
                                                </div>  
                                            </CommandItemTemplate>  
                                            <Columns>  
                                                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" Display="false" ReadOnly="true" />  
                                                <telerik:GridBoundColumn DataField="TipoActividad" UniqueName="TipoActividad" HeaderText="Tipo" 
                                                    ReadOnly="true" />  
                                                <telerik:GridBoundColumn DataField="Actividad" UniqueName="Actividad" HeaderText="Actividad" 
                                                    ReadOnly="true" />  
                                                <telerik:GridTemplateColumn UniqueName="Drop" HeaderText="Base" DataField="Drop">  
                                                    <ItemTemplate>  
                                                        <asp:Literal ID="Literal1" runat="server" Text='<%#Eval("Drop") %>' />  
                                                    </ItemTemplate>  
                                                    <EditItemTemplate>  
                                                        <telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="WebBlue" DataSourceID="EntityDataSourceProcesosActividad" 
                                                            DataValueField="ID_ACTI" DataTextField="DE_ACTI" Width="50px" SelectedValue='<%#Bind("Drop") %>' />  
                                                    </EditItemTemplate>  
                                                </telerik:GridTemplateColumn>  
                                                <telerik:GridTemplateColumn UniqueName="Numeric" HeaderText="Tiempos" DataField="Numeric">  
                                                    <ItemTemplate>  
                                                        <asp:Literal ID="Literal2" runat="server" Text='<%#Eval("Numeric") %>' />  
                                                    </ItemTemplate>  
                                                    <EditItemTemplate>  
                                                        <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Skin="WebBlue" 
                                                            Type="Number" ShowSpinButtons="true" IncrementSettings-InterceptArrowKeys="true" 
                                                            NumberFormat-DecimalDigits="0" IncrementSettings-InterceptMouseWheel="true" Width="50px" 
                                                            DbValue='<%# Bind("Numeric") %>' />  
                                                    </EditItemTemplate>  
                                                </telerik:GridTemplateColumn>  
                                                <telerik:GridTemplateColumn UniqueName="Check" HeaderText="Activo" DataField="Check">  
                                                    <ItemTemplate>  
                                                        <asp:Literal ID="Literal3" runat="server" Text='<%#Eval("Check") %>' />  
                                                    </ItemTemplate>  
                                                    <EditItemTemplate>  
                                                        <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("Check") %>' />  
                                                    </EditItemTemplate>  
                                                </telerik:GridTemplateColumn>  
                                            </Columns>  
                                        </MasterTableView>  
                                        <ClientSettings>  
                                            <Selecting AllowRowSelect="True" EnableDragToSelectRows="True" />  
                                        </ClientSettings>  
                                    </telerik:RadGrid>  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    <br />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td colspan="2" align="right">  
                                    <asp:LinkButton ID="LinkButton1" runat="server" Text="Aceptar" CommandName="PerformInsert" /><asp:Literal  
                                        ID="LiteralSpace" runat="server" Text="  " /><asp:LinkButton ID="LinkButton2" runat="server" 
                                            Text="Cancelar" CommandName="Cancel" CausesValidation="False" />  
                                </td>  
                            </tr>  
                            <tr>  
                                <td>  
                                    <br />  
                                </td>  
                            </tr>  
                        </table>  
                    </center>  
                </FormTemplate>  
                <PopUpSettings Modal="True"></PopUpSettings>  
            </EditFormSettings>  
        </MasterTableView>  
    </telerik:RadGrid> 
Pavlina
Telerik team
 answered on 11 Feb 2014
3 answers
93 views
Hello Team,

I have used telerik rad editor in my application.

In my application there are image library, audio library, video library.

I have bound this library with rad editor image manager, video manager, media manager.
(for e.g: used code for bind my library
 rtfEditor.ImageManager.ContentProviderTypeName = typeof(Telerik.ContentProvider.TelerikDBContentOfPhotoManager).AssemblyQualifiedName;
 rtfEditor.MediaManager.ContentProviderTypeName = typeof(Telerik.ContentProvider.TelerikDBContentOfMediaManager).AssemblyQualifiedName;
rtfEditor.FlashManager.ContentProviderTypeName = typeof(Telerik.ContentProvider.TelerikDBContentOfFlashManager).AssemblyQualifiedName;
)

Above all functionality working fine.

Now Problem is that in my database there are folder name or image gallery name or video gallery name is saved but when these folders is bind inside image manager / video manager / medai manager. it is not html decode to display folder or gallery name.

For Example my folder name is <April's obra> inside database I have saved with HTML Encode and its "&lt;April&#39;s Obra&gt;"
but I need to display "April's obra" in folder name.

for other controls like rad grid its automatically HTML decoded.

I have attached here screen shot for it.







Vessy
Telerik team
 answered on 11 Feb 2014
1 answer
73 views
Hi Telerik

I am using a couple lines of css to get the vertical scroll on the left side instead of the right. Putting the css in works as expected but the horizontal scroll now positioned on the right instead of the left most position.


    <style type="text/css">
        .MyRadGrid {
            direction: rtl;           
        }
 
            .MyRadGrid table {
                direction: ltr;
            }          
         
    </style>
 
 
 
<telerik:RadGrid runat="server" ID="RadGridMembers" CssClass="MyRadGrid" AutoGenerateColumns="false" Width="970px" Height="560px" AllowSorting="true" >
                <ClientSettings Scrolling-UseStaticHeaders="true" Scrolling-AllowScroll="true"  />
                <MasterTableView runat="server" AllowFilteringByColumn="true" EditMode="EditForms" DataKeyNames="FamilyId, MemberId" TableLayout="Fixed" Width="100%">
 
...
...
 
                </MasterTableView>
            </telerik:RadGrid>

The bold css for the rtl moved the vertical scroll but also adjust the hor scroll to the right. Is there a way i can move that hor scroll back to the left? Any css needed?

Thanks!


Maria Ilieva
Telerik team
 answered on 11 Feb 2014
10 answers
497 views
hi my dear friends:

How Can I Show Just Date In A BoundColumn (Date Format In SQL Server 2008 Not DateTime) In Rad ComboBox?

we do not have any DataFormatString For A Bound Column here Like In RadGrid....
Ken
Top achievements
Rank 1
 answered on 11 Feb 2014
4 answers
113 views
Hi,

I'm simply looking to return the text from a listview where I have an id for the key field and a name field which is what is displayed.  I thought this would be relatively simple but keep failing. 

Also I can't seem to find a way to get the first item selected by default when the page loads.

I thought for sue I could find something like this in the forums but came up empty.

Thanks
Eyup
Telerik team
 answered on 11 Feb 2014
6 answers
464 views
Hi There,

I was trying to find CheckBox in the form using below code. When user clicks on the "SAVE" button, if user does not check checkbox in the form, it should ask user to select the "CheckBox" using Message box(Yes\No). If user selects "Yes" then it should automatically check the CheckBox. Please help. 

ASPX file

<%@ Page Title="" Language="C#" MasterPageFile="~/DefaultMaster.master" AutoEventWireup="true" CodeFile="ContentDetail.aspx.cs" Inherits="ContentDetailPage" %>
<%@ MasterType VirtualPath="~/DefaultMaster.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
function CheckBeforeDelete(sender, args) {
args.set_cancel(!window.confirm("Are you sure you would like to delete this record?"));
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Skin="Default" runat="server"
MinDisplayTime="1000" InitialDelayTime="0">
</telerik:RadAjaxLoadingPanel>

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" />

<telerik:RadWindow ID="confirmWindow" runat="server" VisibleTitlebar="true" VisibleStatusbar="false"
Modal="true" Behaviors="None" Height="150px" Width="300px">
<ContentTemplate>
<div style="padding-left: 30px; padding-top: 20px; width: 200px; float: left;">
<asp:Label ID="lblConfirm" Font-Size="14px" Text="Is this the Content change?" runat="server"></asp:Label>
<br />
<br />
<telerik:RadButton ID="RadButtonYes" runat="server" Text="Yes" AutoPostBack="false"
OnClientClicked="confirmResult" >
</telerik:RadButton>

<telerik:RadButton ID="RadButtonNo" runat="server" Text="No" AutoPostBack="false"
OnClientClicked="confirmResult">
</telerik:RadButton>
</div>
</ContentTemplate>
</telerik:RadWindow>

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ContentId" DefaultMode="Edit"
DataSourceID="DocumentContentDataSource" ondatabound="FormView1_DataBound"
onitemdeleted="FormView1_ItemDeleted" onprerender="FormView1_PreRender"
>
<EditItemTemplate>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("VersionId") %>' />
<asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Bind("ParentContentId") %>' />
<asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Bind("Level") %>' />
<asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Bind("CreatedBy") %>' />
<asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Bind("CreatedDate") %>' />
<asp:HiddenField ID="HiddenField8" runat="server" Value='<%# Bind("LastUpdatedBy") %>' />
<asp:HiddenField ID="HiddenField7" runat="server" Value='<%# Bind("LastUpdatedDate") %>' />
<asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Bind("SortNo") %>' />
<asp:HiddenField ID="HiddenField9" runat="server" Value='<%# Bind("HierarchySortNo") %>' />
<table>
<tr style="height:30px">
<td>
<span class="label">Context:&nbsp;</span>
</td>
<td>
<asp:Label ID="LabelParent" CssClass="label" runat="server" />
</td>
</tr>
<tr>
<td>
<span class="label">Section Type:</span>
</td>
<td>
<asp:Label ID="LabelSectionType" CssClass="label" Text='<%# Eval("SectionType") %>' runat="server" />
</td>
</tr>
<tr>
<td>
<span class="label">Section Name:&nbsp;</span>
</td>
<td>
<telerik:RadTextBox ID="RadTextBoxContentName" Width="450px" Runat="server"
Text='<%# Bind("ContentName") %>'>
</telerik:RadTextBox>&nbsp;&nbsp;
<telerik:RadButton ID="RadButtonIsMandatory" runat="server" Text="Mandatory" ToggleType="CheckBox"
ButtonType="ToggleButton" Checked='<%# Bind("IsMandatory") %>' Width="60px">
</telerik:RadButton>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
ControlToValidate="RadTextBoxContentName" ErrorMessage="Enter a section name"
CssClass="validate-warning">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="label">Section Title:&nbsp;</span>
</td>
<td>
<telerik:RadTextBox ID="RadTextBoxContentLabel" Width="450px" Runat="server"
Text='<%# Bind("ContentLabel") %>'>
</telerik:RadTextBox>&nbsp;&nbsp;
<telerik:RadButton ID="RadButtonContentChanged" runat="server" Text="Content Change?" ToggleType="CheckBox"
ButtonType="ToggleButton" Checked='<%# Bind("ContentChangedInd") %>' Width="95px">
</telerik:RadButton>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic"
ControlToValidate="RadTextBoxContentLabel" ErrorMessage="Enter a section title"
CssClass="validate-warning">
</asp:RequiredFieldValidator>

</td>
</tr>
</table>
<table style="margin-top:10px">
</table>
<table style="margin-top:10px">
<tr>
<td>
<span class="label">Created:&nbsp;</span>
</td>
<td>
<asp:Label ID="Label1" CssClass="label" runat="server"
Text='<%# Eval("CreatedByUser.DisplayName") + " On " + Eval("CreatedDate") %>' />
</td>
<td style="padding-left:30px">
<span class="label">Last Updated:&nbsp;</span>
</td>
<td>
<asp:Label ID="Label2" CssClass="label" runat="server"
Text='<%# Eval("LastUpdatedByUser.DisplayName") + " On " + Eval("LastUpdatedDate") %>' />
</td>
</tr>
</table>
<div style="margin-top:10px">
<table>
<tr>
<td>
<telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Bind("Content") %>'
StripFormattingOptions="MsWord,Span,Css,ConvertWordLists" Width="625px" ToolsFile="~/RadEditorToolsFile.xml" ImageManager-ViewPaths="~/UserImages">
<CssFiles>
<telerik:EditorCssFile Value="~/Styles/radeditor.css" />
</CssFiles>
<Tools>
<telerik:EditorToolGroup>
<telerik:EditorTool Name="InsertDocumentLink" Text="Insert Within Document Link" />
</telerik:EditorToolGroup>
</Tools>
</telerik:RadEditor>
<script type="text/javascript">
Telerik.Web.UI.Editor.CommandList["InsertDocumentLink"] = function (commandName, editor, args) {

var myCallbackFunction = function (sender, args) {
editor.pasteHtml(String.format("<a href=#{0}>{1}</a> ", args.templateId, args.label))
}

editor.showExternalDialog(
'DocumentLinkBuilder.aspx',
null,
350,
300,
myCallbackFunction,
null,
'Insert Document Link',
true,
Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
true,
true);
};

function showConfirmRadWindow(sender, args) {

$find("<%=confirmWindow.ClientID %>").show();

$find("<%=RadButtonYes.ClientID %>").focus();

args.set_cancel(true);

}


function confirmResult(sender, args) {

var oWnd = $find("<%=confirmWindow.ClientID %>");

oWnd.close();

if (sender.get_text() == "Yes") {

//var CheckBoxContentChange = '<%=FormView1.FindControl("RadButtonContentChanged").ClientID%>'
//var CheckBoxContentChange = document.getElementById('<%=FormView1.FindControl("RadButtonContentChanged").ClientID%>');
var CheckBoxContentChange = '<%= DirectCast(FormView1.FindControl("RadButtonContentChanged").ClientID)%>'
alert(CheckBoxContentChange);

//$find("<%=RadButtonYes.ClientID %>").click();

}

}

//This code need to be deleted
//function confirmCallBackFn(arg) {
// alert(arg);
//}

</script>
</td>
<td style="padding-left:15px; vertical-align:top">
<asp:Panel ID="PanelBusinessLineDocumentContent" runat="server">
<div class="section" style="width:475px">
<div class="section-header">
<span class="label">LOB Applicable</span>
</div>
<div style="padding:5px">
<table>
<tr>
<td>
<telerik:RadComboBox ID="RadComboBoxBusinessLine" runat="server"
DataTextField="BusinessLineName" DataValueField="BusinessLineId" Width="300px">
</telerik:RadComboBox>
<telerik:RadButton ID="RadButtonAddBusinessLine" runat="server" Text="Add"
onclick="RadButtonAddBusinessLine_Click" Width="60px" CssClass="document-maint-detail-oneoff">
</telerik:RadButton>
<telerik:RadButton ID="RadButtonAddAllBusinessLine" runat="server" Text="Add All"
onclick="RadButtonAddAllBusinessLine_Click" Width="60px" CssClass="document-maint-detail-oneoff">
</telerik:RadButton>
</td>
</tr>
<tr>
<td style="padding-top:5px">
<telerik:RadGrid ID="RadGridBusinessLineDocumentContent" runat="server"
AutoGenerateColumns="False" GridLines="None" Height="330px" Width="460px">
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView DataKeyNames="BusinessLineId">
<Columns>
<telerik:GridTemplateColumn>
<HeaderTemplate>
<asp:LinkButton ID="LinkButtonRemove" runat="server" Text="Remove"
OnClick="LinkButtonRemoveAllBusinessLines_Click" ToolTip="Click to remove all">
</asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButtonRemove" runat="server" CommandArgument='<%# Eval("BusinessLineId") %>'
Text="Remove" OnClick="LinkButtonRemoveBusinessLine_Click">
</asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="BusinessLineId" Visible="false" UniqueName="BusinessLineId" />
<telerik:GridBoundColumn DataField="BusinessLineName" HeaderText="Business Line" UniqueName="BusinessLineName" />
<telerik:GridBoundColumn DataField="ApplicableText" HeaderText="Applicable?" UniqueName="ApplicableText">
<ItemStyle Width="75px" />
</telerik:GridBoundColumn>
</Columns>
<NoRecordsTemplate>
<i><span style="padding-left:2px">No business lines apply</span></i>
</NoRecordsTemplate>
</MasterTableView>
</telerik:RadGrid>
</td>
</tr>
</table>
</div>
</div>
</asp:Panel>
</td>
</tr>
</table>
</div>
<br />
<telerik:RadButton ID="RadButtonSave" runat="server" Text="Save" ButtonType="LinkButton"
CommandName="Update" CausesValidation="true" CssClass="std-button"
OnClientClicking="showConfirmRadWindow"
>
</telerik:RadButton>
<telerik:RadButton ID="RadButtonDelete" runat="server" Text="Delete" ButtonType="LinkButton"
CommandName="Delete" CausesValidation="True" CssClass="std-button" OnClientClicking="CheckBeforeDelete">
</telerik:RadButton>&nbsp;
<telerik:RadButton ID="RadButtonCancel" runat="server" Text="Back" ButtonType="LinkButton"
CommandName="Cancel" CausesValidation="False" CssClass="std-button" onclick="RadButtonCancel_Click">
</telerik:RadButton>&nbsp;
<telerik:RadButton ID="RadButtonAddNew" runat="server" Text="Add New" ButtonType="LinkButton"
CausesValidation="False" CssClass="std-button" NavigateUrl="~/Content/ContentDetail.aspx">
</telerik:RadButton>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td>
<span class="label">Version:&nbsp;</span>
</td>
<td>
<telerik:RadTextBox ID="RadTextBoxVersion" Width="200px" Runat="server" Enabled="false">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td>
<span class="label">Section Name:&nbsp;</span>
</td>
<td>
<telerik:RadTextBox ID="RadTextBoxContentName" Width="450px" Runat="server"
Text='<%# Bind("ContentName") %>'>
</telerik:RadTextBox>&nbsp;&nbsp;
<telerik:RadButton ID="RadButtonIsMandatory" runat="server" Text="Mandatory" ToggleType="CheckBox"
ButtonType="ToggleButton" Checked='<%# Bind("IsMandatory") %>' Width="60px">
</telerik:RadButton>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
ControlToValidate="RadTextBoxContentName" ErrorMessage="Enter a section name"
CssClass="validate-warning" ValidationGroup="OnInsert">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="label">Section Title:&nbsp;</span>
</td>
<td>
<telerik:RadTextBox ID="RadTextBoxContentLabel" Width="450px" Runat="server"
Text='<%# Bind("ContentLabel") %>'>
</telerik:RadTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic"
ControlToValidate="RadTextBoxContentLabel" ErrorMessage="Enter a section title"
CssClass="validate-warning" ValidationGroup="OnInsert">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<span class="label">Chapter:&nbsp;</span>
</td>
<td>
<telerik:RadComboBox ID="RadComboBoxChapter" runat="server"
DataTextField="ContentLabel" DataValueField="ContentId"
AutoPostBack="true" AppendDataBoundItems="true"
onselectedindexchanged="RadComboBoxChapter_SelectedIndexChanged">
<Items>
<telerik:RadComboBoxItem Text="" Value="-1" />
</Items>
</telerik:RadComboBox>
</td>
</tr>
<tr>
<td>
<span class="label">Heading:&nbsp;</span>
</td>
<td>
<telerik:RadComboBox ID="RadComboBoxHeading" runat="server"
DataTextField="ContentLabel" DataValueField="ContentId"
AutoPostBack="true" AppendDataBoundItems="true">
<Items>
<telerik:RadComboBoxItem Text="" Value="-1" />
</Items>
</telerik:RadComboBox>
</td>
</tr>
</table>
<div style="margin-top:10px">
<telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Bind("Content") %>'
StripFormattingOptions="MsWord,Span,Css,ConvertWordLists">
<CssFiles>
<telerik:EditorCssFile Value="~/Styles/radeditor.css" />
</CssFiles>
</telerik:RadEditor>
</div>
<br />
<telerik:RadButton ID="RadButtonSave" runat="server" Text="Save" ButtonType="LinkButton"
CommandName="Insert" CausesValidation="true" CssClass="std-button" ValidationGroup="OnInsert" >
</telerik:RadButton>&nbsp;
<telerik:RadButton ID="RadButtonCancel" runat="server" Text="Back" ButtonType="LinkButton"
CommandName="Cancel" CausesValidation="False" CssClass="std-button" onclick="RadButtonCancel_Click">
</telerik:RadButton>
</InsertItemTemplate>
<ItemTemplate>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("VersionId") %>' />
<asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Bind("ParentContentId") %>' />
<asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Bind("Level") %>' />
<asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Bind("CreatedBy") %>' />
<asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Bind("CreatedDate") %>' />
<asp:HiddenField ID="HiddenField8" runat="server" Value='<%# Bind("LastUpdatedBy") %>' />
<asp:HiddenField ID="HiddenField7" runat="server" Value='<%# Bind("LastUpdatedDate") %>' />
<asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Bind("SortNo") %>' />
<asp:HiddenField ID="HiddenField9" runat="server" Value='<%# Bind("HierarchySortNo") %>' />
<table>
<tr style="height:30px">
<td>
<span class="label">Context:&nbsp;</span>
</td>
<td>
<asp:Label ID="LabelParent" CssClass="label" runat="server" />
</td>
</tr>
<tr>
<td>
<span class="label">Section Type:</span>
</td>
<td>
<asp:Label ID="LabelSectionType" CssClass="label" Text='<%# Eval("SectionType") %>' runat="server" />
</td>
</tr>
<tr>
<td>
<span class="label">Section Name:&nbsp;</span>
</td>
<td>
<telerik:RadTextBox ID="RadTextBoxContentName" Width="450px" Runat="server"
Text='<%# Bind("ContentName") %>' Enabled="false">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td>
<span class="label">Section Title:&nbsp;</span>
</td>
<td>
<telerik:RadTextBox ID="RadTextBoxContentLabel" Width="450px" Runat="server"
Text='<%# Bind("ContentLabel") %>' Enabled="false">
</telerik:RadTextBox>
</td>
</tr>
<tr>
<td>
<span class="label">Mandatory:&nbsp;</span>
</td>
<td>
<asp:Label ID="Label3" CssClass="label" Text='<%# Eval("IsMandatoryText") %>' runat="server" />
</td>
</tr>
</table>
<table style="margin-top:10px">
</table>
<table style="margin-top:10px">
<tr>
<td>
<span class="label">Created:&nbsp;</span>
</td>
<td>
<asp:Label ID="Label1" CssClass="label" runat="server"
Text='<%# Eval("CreatedByUser.DisplayName") + " On " + Eval("CreatedDate") %>' />
</td>
<td style="padding-left:30px">
<span class="label">Last Updated:&nbsp;</span>
</td>
<td>
<asp:Label ID="Label2" CssClass="label" runat="server"
Text='<%# Eval("LastUpdatedByUser.DisplayName") + " On " + Eval("LastUpdatedDate") %>' />
</td>
</tr>
</table>
<div style="margin-top:10px">
<table>
<tr>
<td>
<telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Bind("Content") %>' Enabled="false"
StripFormattingOptions="MsWord,Span,Css,ConvertWordLists" Width="625px" ToolsFile="~/RadEditorToolsFile.xml" ImageManager-ViewPaths="~/UserImages">
<CssFiles>
<telerik:EditorCssFile Value="~/Styles/radeditor.css" />
</CssFiles>
<Tools>
<telerik:EditorToolGroup>
<telerik:EditorTool Name="InsertDocumentLink" Text="Insert Within Document Link" />
</telerik:EditorToolGroup>
</Tools>
</telerik:RadEditor>
</td>
<td style="padding-left:15px; vertical-align:top">
<asp:Panel ID="PanelBusinessLineDocumentContent" runat="server">
<div class="section" style="width:475px">
<div class="section-header">
<span class="label">LOB Applicable</span>
</div>
<div style="padding:5px">
<table>
<tr>
<td style="padding-top:5px">
<telerik:RadGrid ID="RadGridBusinessLineDocumentContent" runat="server"
AutoGenerateColumns="False" GridLines="None" Height="330px" Width="460px">
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView DataKeyNames="BusinessLineId">
<Columns>
<telerik:GridBoundColumn DataField="BusinessLineId" Visible="false" UniqueName="BusinessLineId" />
<telerik:GridBoundColumn DataField="BusinessLineName" HeaderText="Business Line" UniqueName="BusinessLineName" />
<telerik:GridBoundColumn DataField="ApplicableText" HeaderText="Applicable?" UniqueName="ApplicableText">
<ItemStyle Width="75px" />
</telerik:GridBoundColumn>
</Columns>
<NoRecordsTemplate>
<i><span style="padding-left:2px">No business lines apply</span></i>
</NoRecordsTemplate>
</MasterTableView>
</telerik:RadGrid>
</td>
</tr>
</table>
</div>
</div>
</asp:Panel>
</td>
</tr>
</table>
</div>
<br />
<telerik:RadButton ID="RadButtonCancel" runat="server" Text="Back" ButtonType="LinkButton"
CommandName="Cancel" CausesValidation="False" CssClass="std-button" onclick="RadButtonCancel_Click">
</telerik:RadButton>
</ItemTemplate>
</asp:FormView>

<asp:EntityDataSource ID="DocumentContentDataSource" runat="server"
ConnectionString="name=CompConEntities" DefaultContainerName="CompConEntities"
EnableDelete="True" EnableFlattening="False" EnableInsert="True"
Include="ParentContent.ParentContent.ParentContent,LastUpdatedByUser,CreatedByUser,DocumentVersion,BusinessLineDocumentContents.BusinessLine,ChildContents"
EnableUpdate="True" EntitySetName="DocumentContents"
AutoGenerateWhereClause="true"
oncontextcreating="Generic_ContextCreating"
onupdating="DocumentContentDataSource_Updating"
oncontextdisposing="Generic_ContextDisposing"
oninserting="DocumentContentDataSource_Inserting"
oninserted="DocumentContentDataSource_Inserted">
<WhereParameters>
<asp:QueryStringParameter Name="ContentId" QueryStringField="cid" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>

<%-- Updated controls are added programmatically in prerender --%>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>

</asp:Content>

.CS file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CompConData;
using Telerik.Web.UI;

public partial class ContentDetailPage : System.Web.UI.Page
{
static log4net.ILog _log = log4net.LogManager.GetLogger(typeof(ContentDetailPage));

CompConEntities _context = null;

protected bool IsReferrerHierarchy
{
get
{
object obj = ViewState["IsReferrerHierarchy"];
if (obj != null)
return (bool)obj;
else
return false;
}

set
{
ViewState["IsReferrerHierarchy"] = value;
}
}

protected int VersionId
{
get
{
object obj = ViewState["VersionId"];
if (obj != null)
return (int)obj;
else
return -1;
}

set
{
ViewState["VersionId"] = value;
}
}

/// <summary>
/// When in insert mode & from hierarchy, this will be the content id to restore
/// </summary>
protected string InsertCancelContentId
{
get
{
object obj = ViewState["InsertCancelContentId"];
if (obj != null)
return (string)obj;
else
return null;
}

set
{
ViewState["InsertCancelContentId"] = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
if (!SecurityController.IsInAdminRole()) throw new CustomSecurityException();

_context = new CompConEntities();

if (!Page.IsPostBack)
{
// Check if from hierarchy
if (Session["FromHierarchy"] != null)
{
this.IsReferrerHierarchy = true;
Session.Remove("FromHierarchy");
}

if (Request.QueryString[Constants.KeyContentId] != null)
{
this.Master.BreadcrumbLabelText = "You are here: Policy Document > Document Maintenance > Detail";

// Switch to read only template if version is in progress
this.SwitchToReadonlyIfShould(Convert.ToInt32(Request.QueryString[Constants.KeyContentId]));
}
else
{
this.Master.BreadcrumbLabelText = "You are here: Policy Document > Document Maintenance > Detail (New)";

this.FormView1.ChangeMode(FormViewMode.Insert);
}
}
}

protected void Page_Unload(object sender, EventArgs e)
{
if (_context != null) _context.Dispose();
}

private void SwitchToReadonlyIfShould(int contentId)
{
var result = _context.DocumentContents.Include("DocumentVersion")
.Where(c => c.ContentId == contentId);

if (result.Count() > 0)
{
if (result.First().DocumentVersion.VersionStatusCode !=
CompConCommon.Constants.STATUS_IN_PROGRESS)
{
this.FormView1.ChangeMode(FormViewMode.ReadOnly);
}
}
}

private void InitializeContentComboBoxes()
{
// Populate chapter level content
List<DocumentContent> documentContentList = _context.DocumentContents
.Where(c => c.DocumentVersion.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
.Where(c => c.Level == 1)
.OrderBy(c => c.SortNo).ToList();

RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxChapter");

radComboBox.DataSource = documentContentList;
radComboBox.DataBind();
}

private void InitializeContentComboBoxesFromContext(string contextAsCommaDelimitedStr)
{
// Get the context into array
char[] seps = { ',' };
string[] contextStrArr = contextAsCommaDelimitedStr.Split(seps);
this.InsertCancelContentId = contextStrArr[contextStrArr.Length - 1];

// Populate chapter level content
List<DocumentContent> documentContentList = _context.DocumentContents
.Where(c => c.DocumentVersion.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
.Where(c => c.Level == 1)
.OrderBy(c => c.SortNo).ToList();

RadComboBox radComboBoxChapter = (RadComboBox)this.FormView1.FindControl("RadComboBoxChapter");
radComboBoxChapter.DataSource = documentContentList;
radComboBoxChapter.DataBind();

if (radComboBoxChapter.Items.Any(i => i.Value == contextStrArr[0]))
{
radComboBoxChapter.SelectedValue = contextStrArr[0];
}

if (radComboBoxChapter.SelectedIndex > 0) // First value is empty
{
// Populate header level content
int chapterContentId = Convert.ToInt32(radComboBoxChapter.SelectedValue);

List<DocumentContent> headingContentList = _context.DocumentContents
.Where(c => c.ParentContentId == chapterContentId)
.OrderBy(c => c.SortNo).ToList();

RadComboBox radComboBoxHeading = (RadComboBox)this.FormView1.FindControl("RadComboBoxHeading");
radComboBoxHeading.DataSource = headingContentList;
radComboBoxHeading.DataBind();

if (contextStrArr.Length > 1)
{
if (radComboBoxHeading.Items.Any(i => i.Value == contextStrArr[1]))
{
radComboBoxHeading.SelectedValue = contextStrArr[1];
}
}
}
}

protected void RadButtonSave_Click(object sender, EventArgs e)
{

}

protected void RadButtonCancel_Click(object sender, EventArgs e)
{
if (this.IsReferrerHierarchy && this.FormView1.CurrentMode == FormViewMode.Edit)
{
Session[Constants.KeyContentId] = this.FormView1.DataKey["ContentId"];
Response.Redirect(string.Format("~/Content/ContentHierarchy.aspx?{0}={1}",
Constants.KeyVersionId,
this.VersionId));
}
else if (this.IsReferrerHierarchy && this.FormView1.CurrentMode == FormViewMode.Insert)
{
Session[Constants.KeyContentId] = this.InsertCancelContentId;
Response.Redirect(string.Format("~/Content/ContentHierarchy.aspx?{0}={1}",
Constants.KeyVersionId,
this.VersionId));
}
else
{
StateRestorer stateRestorer = new StateRestorer();
stateRestorer.MarkShouldRestore();

Response.Redirect("~/Content/ContentList.aspx");
}
}

protected void RadComboBoxChapter_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
if (e.OldValue == e.Value) return;

// Get new data for heading
int parentContentId = Convert.ToInt32(e.Value);

List<DocumentContent> contentList = _context.DocumentContents
.Where(c => c.DocumentVersion.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
.Where(c => c.ParentContentId == parentContentId)
.OrderBy(c => c.SortNo).ToList();

// Rebind heading
RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxHeading");
this.ClearAndRebind(radComboBox, contentList);
}

protected void Generic_ContextCreating(object sender, EntityDataSourceContextCreatingEventArgs e)
{
e.Context = _context;
}

protected void Generic_ContextDisposing(object sender, EntityDataSourceContextDisposingEventArgs e)
{
e.Cancel = true;
}

protected void FormView1_ItemDeleted(object sender, FormViewDeletedEventArgs e)
{
if (e.Exception == null)
{
if (this.IsReferrerHierarchy)
{
Response.Redirect(string.Format("~/Content/ContentHierarchy.aspx?{0}={1}",
Constants.KeyVersionId,
this.VersionId));
}
else
{
Response.Redirect("~/Content/ContentList.aspx");
}
}
}

protected void FormView1_PreRender(object sender, EventArgs e)
{
if (this.FormView1.CurrentMode == FormViewMode.Edit)
{
RadButton radButtonSave = this.FormView1.FindControl("RadButtonSave") as RadButton;
this.RadAjaxManager1.AjaxSettings.AddAjaxSetting(radButtonSave, this.FormView1, this.RadAjaxLoadingPanel1);
}
}

protected void FormView1_DataBound(object sender, EventArgs e)
{
if (this.FormView1.CurrentMode == FormViewMode.Edit)
{
DocumentContent documentContent = (DocumentContent)this.FormView1.DataItem;

// Set version info
this.VersionId = documentContent.VersionId;

// Sets the parent label
this.SetParentLabel(documentContent);

if (documentContent.IsMandatory)
{
Panel panelBusinessLineDocumentContent =
(Panel)this.FormView1.FindControl("PanelBusinessLineDocumentContent");

panelBusinessLineDocumentContent.Visible = false;
}
else
{
// Bind the business line grid
this.BindBusinessLineDocumentContentItems(documentContent);
}

// Disable delete if any child objects exist
if (documentContent.ChildContents != null && documentContent.ChildContents.Count() > 0)
{
RadButton radButton = (RadButton)this.FormView1.FindControl("RadButtonDelete");
radButton.Enabled = false;
}
}
else if (this.FormView1.CurrentMode == FormViewMode.Insert)
{
// Initialize content combo boxes. May have values passed from hierarchy
if (Session["ContentIdHierarchyContext"] != null)
{
this.InitializeContentComboBoxesFromContext(Session["ContentIdHierarchyContext"].ToString());
Session.Remove("ContentIdHierarchyContext");
}
else
{
this.InitializeContentComboBoxes();
}

// Set version info
var version = _context.DocumentVersions
.Where(v => v.VersionStatusCode == CompConCommon.Constants.STATUS_IN_PROGRESS)
.OrderByDescending(v => v.StartDate);

if (version == null || version.Count() == 0)
throw new ApplicationException("Must have version in progress for insert");

this.VersionId = version.First().VersionId;

RadTextBox radTextBox = (RadTextBox)this.FormView1.FindControl("RadTextBoxVersion");
radTextBox.Text = version.First().VersionName;
}
else
{
DocumentContent documentContent = (DocumentContent)this.FormView1.DataItem;

// Set version info
this.VersionId = documentContent.VersionId;

// Sets the parent label
this.SetParentLabel(documentContent);

if (documentContent.IsMandatory)
{
Panel panelBusinessLineDocumentContent =
(Panel)this.FormView1.FindControl("PanelBusinessLineDocumentContent");

panelBusinessLineDocumentContent.Visible = false;
}
else
{
// Bind the business line grid
this.BindBusinessLineDocumentContentItems(documentContent);
}
}
}

/// <summary>
/// Sets the parent information in the form for edit.
/// </summary>
private void SetParentLabel(DocumentContent documentContent)
{
List<string> parentList = new List<string>();

while (documentContent.ParentContent != null)
{
parentList.Add(documentContent.ParentContent.ContentLabel);
documentContent = documentContent.ParentContent;
}

parentList.Reverse();

Label labelParent = (Label)this.FormView1.FindControl("LabelParent");
labelParent.Text = string.Join(" > ", parentList);
}

protected void DocumentContentDataSource_Inserting(object sender, EntityDataSourceChangingEventArgs e)
{
DocumentContent content = (DocumentContent)e.Entity;

// Set user values
content.LastUpdatedBy = SecurityController.GetCurrentUserId();
content.CreatedBy = SecurityController.GetCurrentUserId();

// Set the version
content.VersionId = this.VersionId;

// Set the parent
RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxHeading");

if (radComboBox.SelectedIndex > 0)
{
content.ParentContentId = Convert.ToInt32(radComboBox.SelectedValue);
content.Level = 3;
}
else
{
radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxChapter");

if (radComboBox.SelectedIndex > 0)
{
content.ParentContentId = Convert.ToInt32(radComboBox.SelectedValue);
content.Level = 2;
}
else
{
var root = _context.DocumentContents.Where(c => c.Level == 0)
.Where(c => c.VersionId == this.VersionId);

content.ParentContentId = root.First().ContentId;
content.Level = 1;
}
}
}

protected void DocumentContentDataSource_Inserted(object sender, EntityDataSourceChangedEventArgs e)
{
if (e.Exception == null)
{
DocumentContent item = (DocumentContent)e.Entity;

if (this.IsReferrerHierarchy) Session["FromHierarchy"] = true;

Response.Redirect(string.Format("~/Content/ContentDetail.aspx?{0}={1}",
Constants.KeyContentId,
item.ContentId));
}
}

protected void DocumentContentDataSource_Updating(object sender, EntityDataSourceChangingEventArgs e)
{
DocumentContent content = (DocumentContent)e.Entity;

//This code need to be deletee
//if (!content.ContentChangedInd)
//{
// RadWindowManager1.RadConfirm("Server radconfirm: Are you sure?", "confirmCallBackFn", 330, 180, null, "Server RadConfirm");
//}
content.LastUpdatedBy = SecurityController.GetCurrentUserId();

this.MarkBusinessLineDocumentContentItemsForSave(content.IsMandatory);
}

private void ClearAndRebind(RadComboBox radComboBox, List<DocumentContent> contentList)
{
this.RemoveItemsExceptFirst(radComboBox);

radComboBox.DataSource = contentList;
radComboBox.DataBind();
}

private void RemoveItemsExceptFirst(RadComboBox radComboBox)
{
RadComboBoxItem item = radComboBox.Items[0];
radComboBox.Items.Clear();
radComboBox.Items.Insert(0, item);
}

// Temp method for checkbox check while content is updated
private void Update_Click(object sender, EventArgs e)
{

}

#region Business Line Document Content grid methods

/// <summary>
/// Data item for the business line document content grid.
/// </summary>
class BusinessLineGridItem
{
public int BusinessLineId { get; set; }

public string BusinessLineName { get; set; }

public string ApplicableText { get; set; }
}

protected void LinkButtonRemoveAllBusinessLines_Click(object sender, EventArgs e)
{
// New list to bind
List<BusinessLineGridItem> businessLineGridItemList = new List<BusinessLineGridItem>();

// Rebind the grid
this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

// Rebind the combo box
this.BindBusinessLineDocumentContentComboBoxArea(
businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
}

protected void LinkButtonRemoveBusinessLine_Click(object sender, EventArgs e)
{
// Build the new grid item list
RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
List<BusinessLineGridItem> businessLineGridItemList = this.GetBusinessLineGridItems(radGrid);

// Get the business line id removed
LinkButton linkButton = sender as LinkButton;
int businessLineId = Convert.ToInt32(linkButton.CommandArgument);

// Get new list without that one item
businessLineGridItemList = businessLineGridItemList.Where(b => b.BusinessLineId != businessLineId).ToList();

// Rebind the grid
this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

// Rebind the combo box
this.BindBusinessLineDocumentContentComboBoxArea(
businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
}

protected void RadButtonAddAllBusinessLine_Click(object sender, EventArgs e)
{
RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
List<BusinessLineGridItem> businessLineGridItemList = this.GetBusinessLineGridItems(radGrid);
List<int> businessLineGridItemIdList = businessLineGridItemList.Select(b => b.BusinessLineId).ToList();

List<BusinessLine> businessLineList = StaticDataCacheManager.GetBusinessLines();
foreach (BusinessLine businessLine in businessLineList)
{
if (!businessLineGridItemIdList.Contains(businessLine.BusinessLineId))
{
businessLineGridItemList.Add(new BusinessLineGridItem()
{
BusinessLineId = businessLine.BusinessLineId,
BusinessLineName = businessLine.BusinessLineName,
ApplicableText = "Yes",
});
}
}

// Rebind the grid
this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

// Rebind the combo box
this.BindBusinessLineDocumentContentComboBoxArea(businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
}

protected void RadButtonAddBusinessLine_Click(object sender, EventArgs e)
{
// Get the selected business line the user wants to add
RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxBusinessLine");
int businessLineId = Convert.ToInt32(radComboBox.SelectedValue);
string businessLineName = radComboBox.Text;

// Create the new grid item & add to the existing grid item list
BusinessLineGridItem newItem = new BusinessLineGridItem();
newItem.BusinessLineId = businessLineId;
newItem.BusinessLineName = businessLineName;
newItem.ApplicableText = "Yes";

RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
List<BusinessLineGridItem> businessLineGridItemList = this.GetBusinessLineGridItems(radGrid);
businessLineGridItemList.Add(newItem);

// Rebind the grid
this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

// Rebind the combo box
this.BindBusinessLineDocumentContentComboBoxArea(businessLineGridItemList.Select(b => b.BusinessLineId).ToList());
}

private void MarkBusinessLineDocumentContentItemsForSave(bool newIsMandatoryValue)
{
int contentId = Convert.ToInt32(this.FormView1.DataKey["ContentId"]);

DocumentContent existingDocumentContent = _context.DocumentContents.Include("BusinessLineDocumentContents")
.Where(c => c.ContentId == contentId).First();

// Change from not mandatory -> mandatory
if (!existingDocumentContent.IsMandatory && newIsMandatoryValue)
{
// Mark all as mandatory
this.AllShouldBeThisApplicableCode(existingDocumentContent, "M");
}
// Change from mandatory -> not mandatory
else if (existingDocumentContent.IsMandatory && !newIsMandatoryValue)
{
// Mark all as applicable
this.AllShouldBeThisApplicableCode(existingDocumentContent, "Y");
}
// Content stays not mandatory
else if (!existingDocumentContent.IsMandatory && !newIsMandatoryValue)
{
RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
List<BusinessLineGridItem> newList = this.GetBusinessLineGridItems(radGrid);

this.MarkBusinessLineDocumentContentItemsForSave(existingDocumentContent,
newList.Select(b => b.BusinessLineId).ToList());
}
}

private void MarkBusinessLineDocumentContentItemsForSave(DocumentContent content, List<int> newBusinessIdList)
{
// Delete those that are currently associated but not in new list.
List<BusinessLineDocumentContent> existingBLDCList =
content.BusinessLineDocumentContents.ToList();

for (int i = 0; i < existingBLDCList.Count; i++)
{
BusinessLineDocumentContent item = existingBLDCList[i];

if (!newBusinessIdList.Contains(item.BusinessLineId))
{
_context.DeleteObject(item);
}
}

// Add those that are not associated but in new list
List<int> existingBLDCIntList =
existingBLDCList.Select(bldc => bldc.BusinessLineId).ToList();

foreach (int newBusinessLineId in newBusinessIdList)
{
if (!existingBLDCIntList.Contains(newBusinessLineId))
{
this.AddNewBusinessLineDocumentToContext(newBusinessLineId, content.ContentId, "Y");
}
}
}

private void AllShouldBeThisApplicableCode(DocumentContent content, string applicableCode)
{
// Mark all currently associated to the given applicable code
foreach (var item in content.BusinessLineDocumentContents)
{
if (item.ApplicableCode != applicableCode) item.ApplicableCode = applicableCode;
}

// Add any business lines that are not associated by getting those items in the all business line
// ids list that are not in the current business line id list
List<int> allBusinessLineIds =
StaticDataCacheManager.GetBusinessLines().Select(b => b.BusinessLineId).ToList();

List<int> unassociatedBusinessLineIds =
allBusinessLineIds.Except(content.BusinessLineDocumentContents.Select(bldv => bldv.BusinessLineId).ToList()).ToList();

foreach (int unassociatedBusinessLineId in unassociatedBusinessLineIds)
this.AddNewBusinessLineDocumentToContext(unassociatedBusinessLineId, content.ContentId, applicableCode);

}

private List<BusinessLineGridItem> GetBusinessLineGridItems(RadGrid radGrid)
{
List<BusinessLineGridItem> list = new List<BusinessLineGridItem>();

foreach (var item in radGrid.MasterTableView.Items)
{
GridDataItem gridDataItem = item as GridDataItem;

BusinessLineGridItem businessLineGridItem = new BusinessLineGridItem();
businessLineGridItem.BusinessLineId = Convert.ToInt32(gridDataItem["BusinessLineId"].Text);
businessLineGridItem.BusinessLineName = gridDataItem["BusinessLineName"].Text;
businessLineGridItem.ApplicableText = gridDataItem["ApplicableText"].Text;

list.Add(businessLineGridItem);
}

return list;
}

private void AddNewBusinessLineDocumentToContext(int businessLineId, int contentId, string applicableCode)
{
BusinessLineDocumentContent newBusinessLineDocumentContent = new BusinessLineDocumentContent();

newBusinessLineDocumentContent.BusinessLineId = businessLineId;
newBusinessLineDocumentContent.ContentId = contentId;
newBusinessLineDocumentContent.ApplicableCode = applicableCode;
newBusinessLineDocumentContent.LastUpdatedBy = SecurityController.GetCurrentUserId();

_context.AddToBusinessLineDocumentContents(newBusinessLineDocumentContent);
}

private void BindBusinessLineDocumentContentItems(DocumentContent documentContent)
{
// Get all applicable business lines
List<BusinessLineDocumentContent> applicableBLDCList = documentContent.BusinessLineDocumentContents.ToList();

// Bind the grid
List<BusinessLineGridItem> businessLineGridItemList =
(from bldc in applicableBLDCList
select
new BusinessLineGridItem {
BusinessLineId = bldc.BusinessLineId,
BusinessLineName = bldc.BusinessLine.BusinessLineName,
ApplicableText = bldc.ApplicableCodeDesc}).ToList();

this.BindBusinessLineDocumentContentGrid(businessLineGridItemList);

if (this.FormView1.CurrentMode == FormViewMode.Edit)
{
// Bind the combo box
this.BindBusinessLineDocumentContentComboBoxArea(
applicableBLDCList.Select(bldc => bldc.BusinessLineId).ToList());
}
}

private void BindBusinessLineDocumentContentGrid(List<BusinessLineGridItem> businessLineGridItemList)
{
// Bind to the grid
RadGrid radGrid = (RadGrid)this.FormView1.FindControl("RadGridBusinessLineDocumentContent");
radGrid.DataSource = businessLineGridItemList.OrderBy(b => b.BusinessLineName).ToList();
radGrid.DataBind();
}

private void BindBusinessLineDocumentContentComboBoxArea(List<int> applicableBLDCIdList)
{
List<BusinessLine> businessLineList = StaticDataCacheManager.GetBusinessLines();

List<BusinessLine> bindBusinessLineList = new List<BusinessLine>();

foreach (BusinessLine businessLine in businessLineList)
{
if (!applicableBLDCIdList.Contains(businessLine.BusinessLineId))
{
bindBusinessLineList.Add(businessLine);
}
}

// combobox
RadComboBox radComboBox = (RadComboBox)this.FormView1.FindControl("RadComboBoxBusinessLine");
radComboBox.DataSource = bindBusinessLineList.OrderBy(b => b.BusinessLineName).ToList();
radComboBox.DataBind();
radComboBox.Enabled = (bindBusinessLineList.Count() > 0);

// add business line button
RadButton radButtonAdd = (RadButton)this.FormView1.FindControl("RadButtonAddBusinessLine");
radButtonAdd.Enabled = (bindBusinessLineList.Count() > 0);

// add all business line button
RadButton radButtonAddAll = (RadButton)this.FormView1.FindControl("RadButtonAddAllBusinessLine");
radButtonAddAll.Enabled = (bindBusinessLineList.Count() > 0);
}

#endregion
}

Thanks,
S

Shyam
Top achievements
Rank 1
 answered on 11 Feb 2014
2 answers
100 views
Hi All,
         I have two detail Tables in my RadGrid . when I am exporting it in excel the bad image of paging icons are also getting exported in excel.
        these bad images are exporting only for those child grids which have data in it.  please let me know what I am doing wrong.  my code behind code is

I have also attached the excel sheet which having these bad images Please find them


  private void ExportDataToFile()
    {
        RadGrid.MasterTableView.ExpandCollapseColumn.Display = false;
        RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
        RadGrid1.MasterTableView.DetailTables[0].ExpandCollapseColumn.Display = false;
        RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].ExpandCollapseColumn.Display = false;
        RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].ShowFooter  = false;
        RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].ShowGroupFooter= false;
        RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].PagerStyle.Visible  = false;
        RadGrid1.ExportSettings.IgnorePaging = true;
        RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].AllowPaging = false;
        //RadGrid1.MasterTableView.DetailTables[0].DetailTables[0].PagingManager. = false;
     
    }

protected void ExportToExcelImageButton_Click(object sender, EventArgs e)
    {
        ExportDataToFile();
        ExportToExcel(RadGrid1, "GridResults");
    }

RadGrid searchRadGrid, String fileName,)
        {
            if (isActionColumn)
                searchRadGrid.MasterTableView.Columns.FindByUniqueName(columnUniqueName).Display = false;
            searchRadGrid.MasterTableView.HierarchyDefaultExpanded = true;
            searchRadGrid.MasterTableView.DetailTables[0].DetailTables[0].AllowPaging =  false;
            searchRadGrid.MasterTableView.DetailTables[0].DetailTables[0].AllowCustomPaging  = false;
            if (searchRadGrid.MasterTableView.HasDetailTables)
            {
                foreach (GridTableView gridTableView in searchRadGrid.MasterTableView.DetailTables)
                {
                    // Added by partner CB to Fix defect 15597 
                    gridTableView.AllowPaging = false;
                    gridTableView.HierarchyDefaultExpanded = true;
                    gridTableView.AllowPaging = false;
                }
            }
            searchRadGrid.ExcelExportCellFormatting += new OnExcelExportCellFormattingEventHandler(SearchRadGrid_ExcelExportCellFormatting);
            searchRadGrid.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
            searchRadGrid.ExportSettings.ExportOnlyData = true;
            searchRadGrid.ExportSettings.IgnorePaging = true;
            searchRadGrid.ExportSettings.OpenInNewWindow = true;
            searchRadGrid.ExportSettings.FileName = fileName;
            _isExport = true;
            searchRadGrid.MasterTableView.ExportToExcel();
        }
Thanks







Shinu
Top achievements
Rank 2
 answered on 11 Feb 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?