Telerik Forums
UI for ASP.NET AJAX Forum
0 answers
82 views
I created my own  "Template" column. Everything works ok. But when I add a child hierarchy and expand any row, the values of that column in the father grid are lost.

Any suggestions on this?

I added part of my code to show the situation.

Code:

public class MyGridTemplateColumn : GridTemplateColumn
{
    public override void Initialize()
    {
        base.Initialize();

        HeaderStyle.Width = Unit.Pixel(105);
        HeaderText = "State";
        UniqueName = "StateCol";

        DataField = "StateId";
        DataType = typeof(byte);

        var _dataSource = new List<KeyValuePair<int, string>>
        {
            new KeyValuePair<int, string>(1, "Active"),
            new KeyValuePair<int, string>(2, "Deleted"),
            new KeyValuePair<int, string>(3, "Inactive"),
            new KeyValuePair<int, string>(6, "Other")
        };

        ItemTemplate = new MyItemTemplate(this.DataField, _dataSource);
        EditItemTemplate = new MyEditItemTemplate(this.DataField, _dataSource);
    }

    public override GridColumn Clone()
    {
        var res = new MyGridTemplateColumn();
        res.CopyBaseProperties(this);

        return res;
    }

    private class MyItemTemplate : ITemplate
    {
        private readonly string _dataField;
        private readonly List<KeyValuePair<int, string>> _dataSource = new List<KeyValuePair<int, string>>();

        public MyItemTemplate(string dataField, List<KeyValuePair<int, string>> origenDatos)
        {
            _dataField = dataField;
            _dataSource = origenDatos;
        }

        public void InstantiateIn(System.Web.UI.Control container)
        {
            var lControl = new LiteralControl { ID = _dataField + "_lControl" };
            lControl.DataBinding += lControl_DataBinding;
            container.Controls.Add(lControl);
        }

        private void lControl_DataBinding(object sender, EventArgs e)
        {
            var l = (LiteralControl)sender;
            var value = l.NamingContainer.GetFieldValue("DataItem." + _dataField);
            if (value != null)
                l.Text = _dataSource.FirstOrDefault(s=>s.Key == (int)value).Value;
        }
    }

    private class MyEditItemTemplate : IBindableTemplate
    {
        private readonly string _dataField;
        private readonly List<KeyValuePair<int, string>> _dataSource = new List<KeyValuePair<int, string>>();

        public MyEditItemTemplate(string dataField, List<KeyValuePair<int, string>> origenDatos)
        {
            _dataField = dataField;
            _dataSource = origenDatos;
        }

        public void InstantiateIn(System.Web.UI.Control container)
        {
            var rcBox = new RadComboBox
            {
                ID = _dataField + "_RadComboBox",
                DataTextField = "Value",
                DataValueField = "Key",
                DataSource = _dataSource
            };

            rcBox.DataBinding += rcBox_DataBinding;
            container.Controls.Add(rcBox);
        }

        public IOrderedDictionary ExtractValues(Control container)
        {
            var dictionary = new OrderedDictionary
            {
                {_dataField, (container.FindControl(_dataField + "_RadComboBox") as RadComboBox).SelectedValue}
            };
            return dictionary;
        }

        private void rcBox_DataBinding(object sender, EventArgs e)
        {
            var rcBox = (RadComboBox)sender;
            var value = rcBox.NamingContainer.GetFieldValue("DataItem." + _dataField);
            rcBox.SelectedValue = value != null ? value.ToString() : string.Empty;
        }
    }
}

Usage:

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="LinqDataSource1" AllowPaging="True" AutoGenerateColumns="False" Width="50%">
    <MasterTableView DataKeyNames="ENTUserAccountId" DataSourceID="LinqDataSource1" PageSize="5">
        <Columns>
            <telerik:GridBoundColumn DataField="UserName" HeaderText="UserName" UniqueName="UserName"/>
            <telerik:GridBoundColumn DataField="Email" HeaderText="Email" UniqueName="Email"/>
            <a:MyGridTemplateColumn />
        </Columns>
        <DetailTables>
            <telerik:GridTableView runat="server" DataSourceID="LinqDataSource2" DataKeyNames="ENTUserAccountId">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="ENTUserAccountId" MasterKeyField="ENTUserAccountId" />
                </ParentTableRelation>
                <Columns>
                    <telerik:GridTemplateColumn DataField="ENTRoleId" HeaderText="Rol" UniqueName="ENTRoleId">
                        <ItemTemplate>
                            <asp:Label ID="ENTRoleIdLabel" runat="server" Text='<%# Eval("ENTRole.RoleName") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>                 
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>

<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="TelerikWebApp1.DataClasses1DataContext"
    EntityTypeName="" TableName="ENTUserAccount"/>
        
<asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="TelerikWebApp1.DataClasses1DataContext"
    EntityTypeName="" TableName="ENTRoleUserAccount" Where="ENTUserAccountId == @ENTUserAccountId">
        <WhereParameters>
            <asp:SessionParameter Name="ENTUserAccountId" Type="Int32" />
        </WhereParameters>
</asp:LinqDataSource>  

Delvis
Top achievements
Rank 1
 asked on 03 Mar 2015
5 answers
796 views
Hello,

I am getting issue to customize group header, I have some operation(sum,count,min,max, last, first, average) in footer.
But I want to do same operation in group header.  Example: I have last product in footer now I want to show total product count in header.
How can I do this? 

[I can have max 3 column for grouping]

Could you please help me anyone?
Please see attached image.
Youssef
Top achievements
Rank 1
 answered on 02 Mar 2015
3 answers
398 views
we need to change skin dynamically for all controls in web application. i have not found appropriate solution for web application. Kindly provide a solution which would be helpful for me.
Thanks,
Rajender..
David
Top achievements
Rank 1
 answered on 02 Mar 2015
4 answers
106 views
Hi, we are in the process of upgrading some grids from Infragistics Ultrawebgrid  to Telerik Controls.  We are under some time constraints due to enforced IE11 upgrade.  The grid I am working with is very simple.  It is straight data entry of requsition details.  It can be one or many lines.  Is the RadGrid appropriate for this?  I have tried using it and am struggling a bit.  I don't want to bind to a data source as there won't be any data on inital load of the screen.  When the user is done inputting all of the data, I then want to insert detail lines into database.  How do I create a simple input grid?

Thanks and sorry for such a rookie question!
C
Top achievements
Rank 1
 answered on 02 Mar 2015
2 answers
108 views
In my tree, the leaves are the data carriers, but I want a click on a particular node to (visually) select itself and all its descending nodes. I am then using the list of selected nodes in an Ajax request.

But I haven't been able to figure out how to accomplish this.

I started out by selecting all the node's children:

var toSelect = !node.get_selected();

if (toSelect)
                node.select();
            else
                node.unselect();

 children.forEach(function(child) {
                if (toSelect )
                    child.select();                    
                else
                    child.unselect();
            });

This does indeed select all the nodes. The problem though, is that it does not show (they don't turn blue). So I was looking for a way to do this through the Telerik client side API, but failed. So I turned to Jquery:

var tree = $find("rtCustomerGroups");
var nodes = tree.get_nodes();

nodes.forEach(function(node) {
if (node.get_selected())
node.addClass("rtSelected");
else
node.removeClass("rtSelected");

The problem with this approach is that, while it works visually, the browser does not seem to like it - as it's complaining (sometimes) with a typeError saying addClass/removeClass aren't functions.

This also breaks the javascript as the next line, calling the Ajax function, never gets run.

This really bugs me, as the selection really works the way I want, including multi selection with ctrl click.

Ivan Danchev
Telerik team
 answered on 02 Mar 2015
2 answers
383 views
We are removing all Infragistic controls from our website and converting them over to Telerik.

I am looking for any tools or information on how to convert UltraWebGrid over to Telerik RadGrid.

Thanks
C
Top achievements
Rank 1
 answered on 02 Mar 2015
5 answers
247 views
I have seen and tried this code that is floating around using this code bit:

<telerik:RadDatePicker ID="RadDatePicker1" runat="server">    
<Calendar runat="server" ShowDayCellToolTips="false">        
<ClientEvents OnLoad="calendarLoad" />    
</Calendar>
</telerik:RadDatePicker>

function calendarLoad(sender, args) {    
$(sender.get_element()).find("[title]").each(function (i, el)
 {        
el.title = "";    });

}

however when i use this code, it DOES remove the title text, but the tooltip still shows up blank. we have deployed the RadTooltipManager in our Master Page. is there some way to mute these blank tooltips from the calendar? is there no setting like ShowDayCellToolTips="false" for the day cells that apply to the navigation and Day of the Week titles?
this is very frustrating. any help would be GREATLY appreciated

thanks in Advance


Web Developer
Top achievements
Rank 1
 answered on 02 Mar 2015
0 answers
81 views
I need to consume a service to CRUD operation and bind the data to RadGrid. I need to understand which of the below two methods will give me good performance or both of them would yield same results.

1. Consume service using client side and bind to the RadGrid - something like demonstrated in this url - http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/insert-update-delete-client/defaultcs.aspx

2. Consume service using code behind (.Net Code) and ajaxfying the events using RadAjaxManager

For both of the above method, the effect would pretty much look the same but i guess there should be some performance difference?





A
Top achievements
Rank 1
 asked on 02 Mar 2015
1 answer
202 views
Is there a way to assign a tooltip or otherwise uniquely identify the spin up / spin down buttons on a RadNumericTextBox?  (Nothing jumps out in the documentation as to how to accomplish this; searches have been fruitless thus far.)

When running JAWS against our application in assistive technology mode, the buttons show up in the JAWS Links List as "Spin Up" and "Spin Down" so that there's no indication of with which control they're associated (see attached).

Daniel
Telerik team
 answered on 02 Mar 2015
1 answer
187 views
Hello,

I have a radGrid that populates with groups. The group header displays the group header title and aggregate sum as expected but the group header text is not aligned under the column name. All the header text is aligned in the left side of the groupheader. My code for calculates the sum is this:

protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            RadGrid1.HeaderStyle.Font.Size = 10;
            RadGrid1.GroupHeaderItemStyle.Font.Size = 10;  
 
            GridGroupByExpression gridGroupByExpression1 = new GridGroupByExpression();
            GridGroupByField gridGroupByField1 = new GridGroupByField();
             
            gridGroupByField1.FieldName = "GroupName";
            gridGroupByField1.HeaderValueSeparator = " ";
 
            gridGroupByExpression1.SelectFields.Add(gridGroupByField1);
            gridGroupByExpression1.GroupByFields.Add(gridGroupByField1);
 
            GridGroupByField gridGroupByField3 = new GridGroupByField();
             
            foreach (totals tot in totalsList)
            {
                gridGroupByField3 = new GridGroupByField();
                gridGroupByField3.FieldName = tot.name;
                gridGroupByField3.HeaderText = " ";
                gridGroupByField3.HeaderValueSeparator = " ";
                gridGroupByField3.FormatString = " (Total: {0})";
                gridGroupByField3.Aggregate = GridAggregateFunction.Sum;
                gridGroupByExpression1.SelectFields.Add(gridGroupByField3);
            }
 
            RadGrid1.MasterTableView.GroupByExpressions.Add(gridGroupByExpression1);
        }

I need to align the sum under the column name inside the groupheader text.

Thank you
Daniel
Telerik team
 answered on 02 Mar 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?