Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
280 views

Hello,

I'm currently looking into using a grid with Batch Editing and custom EditItemTemplates.  I'm running into a wall because I need the custom template for editing to render differently depending on the values in the DataItem object for the row that is being edited.

I've created an example that is attached, and will describe it to hopefully outline what I'm trying to do.  

In a database that contains people, some people are under organizations, and within those organizations are different bosses.  I've created a dictionary that contains the list of bosses for 2 organizations with Id's 0 and 1.  The grid shows a list of people, and if you go to edit the boss selection for any given person I'm trying to have the drop down list display different items in the list depending on the organization id for that person.

Because the DataBinding event does not fire for custom templates that are used on the EditItemTemplate property of a TemplateColumn I'm at a loss on how to do this.  I've thought of creating a new class that inherits the Control class, then overriding the Render() function in hopes that I may be able to access the DataItem through the parent hierarchy but my knowledge of the RadGrid structure isn't enough to figure this out.

Here is a simple example of my code.  I've made comments in the InstantiateIn function with what I'm trying to do.

 

Any help would be greatly appreciated and thanks in advance.

 

TestItemTemplate.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestItemTemplate.aspx.cs" Inherits="Test_TestItemTemplate" %>
 
<!DOCTYPE html>
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="ScriptManager" runat="server" EnableTheming="True">
    </telerik:RadScriptManager>
        <div>
            <asp:Panel runat="server" ID="Panel" >
                <telerik:RadGrid runat="server" ID="grid">
                </telerik:RadGrid>
            </asp:Panel>
        </div>
    </form>
</body>
</html>

 

TestItemTemplate.aspx.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
public partial class Test_TestItemTemplate : Page
{
    private class GridItemTemplate : ITemplate
    {
        string _colName;
        public GridItemTemplate(string colName)
        {
            _colName = colName;
        }
 
        public void InstantiateIn(Control container)
        {
            Label label = new Label();
            label.DataBinding += new EventHandler(Label_DataBinding);
            container.Controls.Add(label);
        }
 
        void Label_DataBinding(object sender, EventArgs e)
        {
            Label label = (Label)sender;
            GridDataItem container = (GridDataItem)label.NamingContainer;
            label.Text = ((DataRowView)container.DataItem)[_colName].ToString();
        }
    }
 
    private class GridEditItemTemplate : ITemplate
    {
        Dictionary<int, List<ListItem>> organizationBosses = new Dictionary<int, List<ListItem>>
        {
            { 0, new List<ListItem> { new ListItem("Harry"), new ListItem("Jim") } },
            { 1, new List<ListItem> { new ListItem("Jen") } }
        };
 
        string _colName;
        public GridEditItemTemplate(string colName)
        {
            _colName = colName;
        }
 
        public void InstantiateIn(Control container)
        {
            DropDownList ddl = new DropDownList();
            // Add the default item
            ddl.Items.Add(new ListItem("Self"));
 
            // This event will never fire to my knowledge
            // ddl.DataBinding += new EventHandler(ddl_databinding);
 
             
            // Somehow get the parent DataItem container upon rendering to retrieve the "OrganizationId" value from the dataitem so I can show the additional items for the Boss drop down list
            // If (OrganizationId == 0)
            // ddl.Items.AddRange(organizationBosses[0].ToArray());
            // Else if (OrganizationId == 1)
            // ddl.Items.AddRange(organizationBosses[1].ToArray());
 
            container.Controls.Add(ddl);
        }
    }
 
    protected void Page_Init(object sender, EventArgs e)
    {
        grid.AutoGenerateColumns = false;
 
        GridBoundColumn boundColumn1 = new GridBoundColumn();
        boundColumn1.DataField = "PersonId";
        boundColumn1.UniqueName = "PersonId";
        boundColumn1.Display = false;
        grid.MasterTableView.Columns.Add(boundColumn1);
        boundColumn1.DataField = "OrganizationId";
        boundColumn1.UniqueName = "OrganizationId";
        boundColumn1.Display = false;
        grid.MasterTableView.Columns.Add(boundColumn1);
        boundColumn1 = new GridBoundColumn();
        boundColumn1.DataField = "FirstName";
        boundColumn1.UniqueName = "FirstName";
        boundColumn1.HeaderText = "First Name";
        grid.MasterTableView.Columns.Add(boundColumn1);
        boundColumn1 = new GridBoundColumn();
        boundColumn1.DataField = "LastName";
        boundColumn1.UniqueName = "LastName";
        boundColumn1.HeaderText = "Last Name";
        grid.MasterTableView.Columns.Add(boundColumn1);
        boundColumn1 = new GridBoundColumn();
        boundColumn1.DataField = "Email";
        boundColumn1.UniqueName = "Email";
        boundColumn1.HeaderText = "Email";
        grid.MasterTableView.Columns.Add(boundColumn1);
 
        GridTemplateColumn templateColumn = new GridTemplateColumn();
        GridItemTemplate itemTemplate = new GridItemTemplate("Boss");
        templateColumn.ItemTemplate = itemTemplate;
        GridEditItemTemplate editItemTemplate = new GridEditItemTemplate("Boss");      
        templateColumn.EditItemTemplate = editItemTemplate;
        templateColumn.HeaderText = "Boss";
        grid.MasterTableView.Columns.Add(templateColumn);
 
        grid.MasterTableView.EditMode = GridEditMode.Batch;
        grid.MasterTableView.BatchEditingSettings.EditType = GridBatchEditingType.Cell;
        grid.MasterTableView.BatchEditingSettings.OpenEditingEvent = GridBatchEditingEventType.Click;
 
        grid.DataSource = GetDataSource();
        grid.AllowPaging = true;
        grid.PageSize = 50;
    }
 
    private DataTable GetDataSource()
    {
        DataTable dataSource = new DataTable();
        dataSource.Columns.AddRange(new DataColumn[] {
            new DataColumn("PersonId"),
            new DataColumn("OrganizationId"),
            new DataColumn("FirstName"),
            new DataColumn("LastName"),
            new DataColumn("Email"),
            new DataColumn("Boss")
        });
 
        dataSource.Rows.Add(new object[] { 0, null, "John", "Doe", "john@doe.com", "Self" });
        dataSource.Rows.Add(new object[] { 1, 0, "Bill", "Carson", "bill@carson.com", "Harry"});
        dataSource.Rows.Add(new object[] { 2, 0, "Jessie", "Jones", "jessie@jones.com", "Jim"});
        dataSource.Rows.Add(new object[] { 3, 1, "Joe", "Schmoe", "joe@schmoe.com", "Jen" });
        dataSource.Rows.Add(new object[] { 4, null, "Sarah", "Conner", "sarah@conner.com", "Self" });
 
        return dataSource;
    }
}

Attila Antal
Telerik team
 answered on 14 Mar 2019
1 answer
119 views

     hi

                I use function OnClientFilesUploaded() in that i call one button click event in the button click i save the file in DB ,after i click the browser back button i check  AsyncUpload1.UploadedFiles.Count=0 in IE,mozila,chrome,opera but in edge AsyncUpload1.UploadedFiles.Count=1 so in this path "E:\MU\AKPKCheckin\App_Data\RadUploadTemp" the file is not there so it through error message "could not find the file...." in that location.

 

Attila Antal
Telerik team
 answered on 14 Mar 2019
1 answer
73 views

Hello,

 

After i updated my Telerik ASP.NET AJAX to the 2018.3.910 version i got some bugs to my site.

 

When i push a tab or a button nothing at all happens and a '#' appears after my link in the URL.

This problem does not happen at all of my pages on my site. I have tried google this problem and looked here at your site but haven't found any solution for it.

I didn't had this problem before i updated the Telerik version.

 

Best regards, Tim

Rumen
Telerik team
 answered on 14 Mar 2019
1 answer
71 views

Hi,

 

The image draghandles are gone in Firefox 65.0.2

Is this a known issue?

 

Marc

Rumen
Telerik team
 answered on 14 Mar 2019
16 answers
631 views
It is really easy to simulate this error.. RadAjaxLoadingPanel won't show up when I put on onserverclick event there
use radajaxpanel and loading panel and put
<button id="butsearch" runat="server" onserverclick="butsearch_Click"  >sss</button>
It will not work, however, if you remove onserverclick event, it will work again

I use
<form runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" CompositeScript-ScriptMode="Release">
            <CdnSettings TelerikCdn="Enabled" />
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                <asp:ScriptReference Path="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js" />
                <asp:ScriptReference Path="~/JQuery/jqeruy.roundcorners.js" />
                <asp:ScriptReference Path="~/JQuery/jquery.general.js" />
                <asp:ScriptReference Path="~/JQuery/jquery.scrollTo.js" />
                <asp:ScriptReference Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    Name="MicrosoftAjax.js" Path="https://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js" />
            </Scripts>
        </telerik:RadScriptManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    <telerik:RadAjaxPanel LoadingPanelID="RadAjaxLoadingPanel1" runat="server">
<button id="butsearch" runat="server" onserverclick="butsearch_Click"  >sss</button>
  </telerik:RadAjaxPanel>
</form>
joe
Top achievements
Rank 1
 answered on 14 Mar 2019
3 answers
114 views
Hi.  when i choose file i get resource error and file not uploaded in cotrol.
Screenshot : http://prntscr.com/mv05mb 

I tried following ways,
 1, removed telerik dll and added again,
 2 removed web config and added upload control again and register radscript also, still problem

Attila Antal
Telerik team
 answered on 14 Mar 2019
4 answers
87 views

I have a web application, with a RadGrid on the default page, published on IIS 10.

When I browse to the application using http://mywebapp it opens up, but I nothing happens when clicking on the edit button on any of the rows in the RadGrid.  When troubleshooting with Fiddler I receive 500 Internal Server Error.

If I include the page name in the address, i.e. http://mywebapp/default.aspx, editing works as expected.

I don't want to include the page name every time I browse to my web application, is there a way to solve this?

Eyup
Telerik team
 answered on 14 Mar 2019
2 answers
241 views
while page loading, "RadAsyncUpload " control not rendering properly for millisecond. it is not applying metrotouch css to file upload contorl for millisecond.
following are the code information
     <telerik:RadAsyncUpload ID="MyFile1" runat="server" MultipleFileSelection="Disabled" Skin="MetroTouch" EnableViewState="true" MaxFileInputsCount="1" 
                                PostbackTriggers="rdbAccreditationCertificateYes,rdbAccreditationCertificateNo,rdbFirewallYes,rdbFirewallNo,rdbIRSYes,rdbIRSNo,rdbYes,rdbNo,Lnkproceed,LnkAddRow,lnkDelete,btnRemove,lnkBack,LnkSaveContinue">
                                <Localization Select="Browse" />
                            </telerik:RadAsyncUpload>

Please refer attached file
anup
Top achievements
Rank 1
 answered on 13 Mar 2019
5 answers
303 views
Hello,
I try to change values of a cell in a radGrid before exporting the grid to Excel as shown below. For testing purpose I set the value to "123". After exporting, Excel does not show "123" at all. Why is that? I try to Rebind() before exporting and it doesn't work either.

Private Sub exp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exp.Click
       For Each rowItem As GridDataItem In RadGrid1.Items
            rowItem ("E").Text = "123"
        Next
       RadGrid1.MasterTableView.ExportToExcel()
End Sub
Geoff
Top achievements
Rank 1
 answered on 12 Mar 2019
3 answers
133 views

When I select a row in the RadGrid, a FormView is populated with the details.  But when I update the data in the FormView, the data is updated in the RadGrid, but the FormView is no longer visible.  I'm guessing because the row selection is lost, even though the selected row remains highlighted due to the js I'm using.  How can I fix this issue?  I just want the row selection on the RadGrid to remain even after I update, insert, or delete data from the FormView, so that the FormView remains visible.

Here's the RadGrid:

<telerik:RadGrid runat="server" ID="rgVendors" DataSourceID="sdsRgVendors" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" ShowGroupPanel="True" OnSelectedIndexChanged="rgVendors_OnSelectedIndexChanged">
                <ClientSettings AllowDragToGroup="True" AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnablePostBackOnRowClick="True">
                    <Selecting AllowRowSelect="True"></Selecting>
                    <ClientEvents OnRowCreated="rgVendors_RowCreated" OnRowSelected="rgVendors_RowSelected" OnRowDeselected="rgVendors_RowDeselected" />
                </ClientSettings>
                <MasterTableView ClientDataKeyNames="venIdPk" DataKeyNames="venIdPk" DataSourceID="sdsRgVendors">
                    <Columns>
                        <telerik:GridBoundColumn DataField="venIdPk" ReadOnly="True" HeaderText="venIdPk" SortExpression="venIdPk" UniqueName="venIdPk" DataType="System.Int32" FilterControlAltText="Filter venIdPk column"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="venNm" HeaderText="Vendor" SortExpression="venNm" UniqueName="venNm" FilterControlAltText="Filter venNm column" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="venAddress" HeaderText="Address" SortExpression="venAddress" UniqueName="venAddress" FilterControlAltText="Filter venAddress column" ReadOnly="True" AllowFiltering="False" AllowSorting="False" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="venCity" HeaderText="City" SortExpression="venCity" UniqueName="venCity" FilterControlAltText="Filter venCity column" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="stateProvAcro" HeaderText="State/Province" SortExpression="stateProvAcro" UniqueName="stateProvAcro" FilterControlAltText="Filter stateProvAcro column" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="venZipCode" HeaderText="Zip Code" SortExpression="venZipCode" UniqueName="venZipCode" FilterControlAltText="Filter venZipCode column" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="venPh" HeaderText="Phone" SortExpression="venPh" UniqueName="venPh" FilterControlAltText="Filter venPh column" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                        <telerik:GridCheckBoxColumn DataField="venActive" HeaderText="Active" SortExpression="venActive" UniqueName="venActive" DataType="System.Boolean" FilterControlAltText="Filter venActive column" AllowFiltering="False" AllowSorting="False" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True" ItemStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
                    </Columns>
                </MasterTableView>
                <AlternatingItemStyle BackColor="#DCDCDC"></AlternatingItemStyle>
            </telerik:RadGrid>

Here's part of the FormView:

<asp:FormView
    runat="server"
    ID="fvVenDets"
    DataKeyNames="venIdPk"
    DataSourceID="sdsFvVenDets"
    OnItemCommand="fvVenDets_OnItemCommand"
    OnItemUpdated="fvVenDets_OnItemUpdated"
    OnItemInserted="fvVenDets_OnItemInserted"
    OnItemDeleted="fvVenDets_OnItemDeleted">
 
    <ItemTemplate>...</ItemTemplate>
    <EditItemTemplate>...</EditItemTemplate>
    <InsertItemTemplate>...</InsertItemTemplate>
 
</asp:FormView>

Here's the js to maintain the row selection:

<script type="text/javascript">
                var selected = {};
 
                function rgVendors_RowSelected(sender, args) {
                    var venid = args.getDataKeyValue("venIdPk");
                    if (!selected[venid]) {
                        selected[venid] = true;
                    }
                }
                function rgVendors_RowDeselected(sender, args) {
                    var venid = args.getDataKeyValue("venIdPk");
                    if (selected[venid]) {
                        selected[venid] = null;
                    }
                }
                function rgVendors_RowCreated(sender, args) {
                    var venid = args.getDataKeyValue("venIdPk");
                    if (selected[venid]) {
                        args.get_gridDataItem().set_selected(true);
                    }
                }   
            </script>
Attila Antal
Telerik team
 answered on 12 Mar 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?