Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
308 views
I have two GridTemplateColumn's inside a RadGrid that is created dynamically in the code behind (there are actually several Grids, all with different datasources, that live inside the child items of a 2-level deep RadPanelBar!). It's a fairly simple senario:

1st column is a "N/A" column that only contains a RadioButton control.
2nd column is a "Date" column that contains a RadioButton and a RadDatePicker.

The desired behavior is for the RadDatePicker to be disabled when the "N/A" button is pressed, and enabled when the "Date" button is pressed. Unfortunately there's no 'onChanged' event for RadioButtons, so it has to be handled by 'onClick' handlers.

Here are template classes for the two columns:

private class RadioButtonDateColumnTemplate : ITemplate
{
    protected RadioButton rButton;
    protected RadDatePicker datePicker;
    private string colname;
    public RadioButtonDateColumnTemplate(string cName)
    {
        colname = cName;
    }
    public void InstantiateIn(System.Web.UI.Control container)
    {
        rButton = new RadioButton();
        rButton.GroupName = "ScaleButtons";
        rButton.ID = "dateButton";
        rButton.DataBinding += new EventHandler(rButton_DataBinding);               
         
        datePicker = new RadDatePicker();
        datePicker.ID = "DatePicker";
        datePicker.DataBinding += new EventHandler(datePicker_DataBinding);
        datePicker.Load += new EventHandler(datePicker_Load);
 
        container.Controls.Add(rButton);
        container.Controls.Add(datePicker);
    }
 
    void datePicker_Load(object sender, EventArgs e)
    {
        rButton.Attributes.Add("onClick", string.Format("DateButtonClicked('{0}')", datePicker.ClientID));
    }
 
    void datePicker_DataBinding(object sender, EventArgs e)
    {
        RadDatePicker dPick = (RadDatePicker)sender;
        GridDataItem container = (GridDataItem)dPick.NamingContainer;
 
        string date = ((DataRowView)container.DataItem)[colname].ToString();
        DateTime dateTime;
 
        if (date == string.Empty)
            dPick.SelectedDate = null;
        else
        {
            DateTime.TryParse(date, out dateTime);
            dPick.SelectedDate = dateTime;
        }
    }
 
    void rButton_DataBinding(object sender, EventArgs e)
    {
        RadioButton rBut = (RadioButton)sender;
        GridDataItem container = (GridDataItem)rBut.NamingContainer;
 
        bool naChecked;
        bool.TryParse(((DataRowView)container.DataItem)["na"].ToString(), out naChecked);
        rButton.Checked = !naChecked;
        datePicker.Enabled = !naChecked;
    }
}


private class RadioButtonColumnTemplate : ITemplate
{
    protected RadioButton rButton;
    private string colname;
    public RadioButtonColumnTemplate(string cName)
    {
        colname = cName;
    }
    public void InstantiateIn(System.Web.UI.Control container)
    {
        rButton = new RadioButton();
        rButton.GroupName = "ScaleButtons";
        rButton.DataBinding += new EventHandler(rButton_DataBinding);
        if (colname == "na")
        {
            rButton.ID = "naButton";
            rButton.Load += new EventHandler(rButton_Load);
        }
 
        container.Controls.Add(rButton);
    }
 
    void rButton_Load(object sender, EventArgs e)
    {
        GridDataItem gridRow = (GridDataItem)rButton.Parent.NamingContainer;
        string gridID = gridRow.OwnerGridID;
        int rowIndex = gridRow.DataSetIndex;
 
        rButton.Attributes.Add("onClick", string.Format("NaButtonClicked('{0}',{1},'Date')", gridID, rowIndex));
    }
 
    void rButton_DataBinding(object sender, EventArgs e)
    {
        RadioButton rBut = (RadioButton)sender;
        GridDataItem container = (GridDataItem)rBut.NamingContainer;
 
        bool check;
        bool.TryParse(((DataRowView)container.DataItem)[colname].ToString(), out check);
        rButton.Checked = check;
    }
}

The RadGrids are created inside a dynamically built RadPanelBar with root and child items (the RadGrids are inside the child items, 1 per child):

protected void CategoriesPanelBar_Init(object sender, EventArgs e)
{
    DataTable cTypes = GetCapabilityTypes(false);
    DataTable cCategories = GetCapabilityCategories();
 
    RadPanelBar rpbCapabilityCategories = (RadPanelBar)sender;
 
    foreach (DataRow typeRow in cTypes.Rows)
    {
        string typeName = typeRow["typename"].ToString();
        string typeID = typeRow["id"].ToString();
        RadPanelItem typeItem = new RadPanelItem(typeName);
        DataRow[] categoriesByType = cCategories.Select(string.Format("type = {0}", typeID));
        foreach (DataRow categoryRow in categoriesByType)
        {
            string categoryName = categoryRow["categoryname"].ToString();
            int categoryID = int.Parse(categoryRow["id"].ToString());
            RadPanelItem categoryItem = new RadPanelItem(categoryName);
            categoryItem.BackColor = System.Drawing.Color.LightBlue;
 
            RadGrid rgItems = new RadGrid();
            rgItems.AutoGenerateColumns = false;
            rgItems.AllowMultiRowEdit = true;
            rgItems.MasterTableView.EditMode = GridEditMode.InPlace;
            rgItems.PreRender += new EventHandler(rgItems_PreRender);
 
            BuildCapabilityItemsGridByCategory(rgItems, categoryID);
 
            categoryItem.Controls.Add(rgItems);
            typeItem.Items.Add(categoryItem);
        }
 
        rpbCapabilityCategories.Items.Add(typeItem);
    }
}


I create the template columns when building the RadGrid inside the BuildCapabilityItemsGridByCategory() function:

...

DataTable dtCapabilities = GetCapabilityItemsByCategoryAndSite(category, site);
 
...
 
dtCapabilities.Columns.Add("na", System.Type.GetType("System.Boolean"));
GridTemplateColumn naCol = new GridTemplateColumn();
naCol.ItemTemplate = new RadioButtonColumnTemplate("na");
naCol.HeaderText = "N/A    ";
naCol.DataField = "na";
rgItems.Columns.Insert(rgItems.Columns.Count, naCol);
 
...
 
GridTemplateColumn dateCol = new GridTemplateColumn();                       
dateCol.ItemTemplate = new RadioButtonDateColumnTemplate("date");
dateCol.HeaderText = "Date";
dateCol.DataField = "date";
dateCol.UniqueName = "Date";
rgItems.Columns.Insert(rgItems.Columns.Count, dateCol);
 
...
 
rgItems.DataSource = dtCapabilities;
rgItems.DataBind();


Now enabling the RadDatePicker was very easy - I can pass the clientID directly to the JavaScript function, so a simple js function works:

function DateButtonClicked(datePickerId) {
         var datePicker = $find(datePickerId)
         datePicker.set_enabled(true);
}

But I had a terrible time trying to get the disable to work!! At first, I tried passing the RadDatePicker clienID to the JavaScript function by getting it in the code behind (which is easier for me to write than JavaScript). I tried getting the "N/A" buttton's GridDataItem and looking for a RadDatePicker control on the same row, but some some reason the event would NEVER show up in the page's markup, even when I could see the attribute being added with what appear to be the correct clientID's for the "N/A" radio button and the RadDatePicker on the same row.

I followed some other examples to create a very round-about solution, passing the entire GridView to the JavaScript function, along with the row index and column name that holds the RadDatePicker I want to disable. Even then, I'm not sure how to access the RadDatePicker directly from its grid cell. I ended up using an ugly hack to parse the clientID out of the .innerHTML of the cell, then using the $find() method to grab it. It works, but I KNOW there has to be a better, safer way of doing this:

function NaButtonClicked(gridID, index, colName) {
   var gridView = $find(gridID);
   var masterTable = gridView.get_masterTableView();
   var cell = masterTable.getCellByColumnUniqueName(masterTable.get_dataItems()[index], colName)
   if (cell != null) {
      var datePickers = cell.getElementsByClassName('RadPicker RadPicker_Default');
      for (i = 0; i < datePickers.length; i++) {
         var idString = datePickers[i].innerHTML;
         var startString = "id=\"";
         var endString = "\"";
         var startIndex = idString.indexOf(startString) + startString.length;
         var endIndex = idString.indexOf(endString, startIndex);
         var datePickerId = idString.substring(startIndex, endIndex);
      }
   }
   var datePicker = $find(datePickerId)
   datePicker.set_enabled(false);
}


My questions are:
- is there an easier way to access the controls living in these template columns? I don't have an easy references to use, because everything is created dynamically (the RadGrid, the columns, etc)
-am I hooking up the JavaScript functions is the right spot in the code behind?

I'm worried I'm going about this in the wrong way, making things unnecessarily hard on myself, but maybe the programmatic approach I'm using is just more difficult to execute. I'm very new to ASP.NET and especially JavaScript coding, so I appreciate any help (and all the help I've already received from Pavlina!).


Thanks,
-Adam
Pavlina
Telerik team
 answered on 26 Sep 2011
1 answer
124 views
http://www.telerik.com/help/aspnet-ajax/grid-filtertemplate.html

Is there a replacement for Checkbox for RadComboBoxSelectedIndexChangedEventArgs?
When I tried the client code version, args is undefined.

<script type="text/javascript">
    function chkFilter_CheckedChanged(sender, args) {
        var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");
        tableView.filter("column", args.get_item().get_value(), "EqualTo");
    }
</script>
Radoslav
Telerik team
 answered on 26 Sep 2011
1 answer
81 views

How to solve change the radgrid default tool tip when site has mutiple langaues?
For example, when french user look at the grid, they want to see tool tip"sort" word in french.

I tried Mygrid.Culture =

 

new System.Globalization.CultureInfo("fr-fr"); it doesn't work.

 

Shinu
Top achievements
Rank 2
 answered on 26 Sep 2011
3 answers
180 views
I have a tooltip that I am using to preview text on all of a customers items in one spot. When an item is added or modified it calls a function that builds the basic html content for the tooltip, like so...(some lines omitted for clarity)

var divReviewAllPers = getElementId('divReviewAllPers');
for
(i = 1; i < arrItems.length; i++) {
            strAllPersText += '<u>Item #' + i + '</u><br />';
            if (i == parseInt(hidItemEdit.value)) {
                // This is the item being edited, so update the master string with the textbox values
                var strNewPersTextItem = '';
                var strItemLines = arrItems[i];
                
                for (x = 0; x < arrLines.length; x++) {
                    if (x < getElementId('hidNumLines').value) {
                        if (strLine == '') {
                            strAllPersText += 'Line ' + (x + 1) + ' - [LINE IS BLANK]<br />';
                        } else {
                            strAllPersText += 'Line ' + (x + 1) + ' - ' + strLine + '<br />';
                        }
                    }
                    strNewPersTextItem += 'Line ' + (x + 1) + ' - [LINE IS BLANK]<br />';
                }
            } else {
                // This is not the item being edited, so put the existing data back in the master string
                if (arrItems[i].length > 0) {
                    for (y = 0; y < arrLines.length; y++) {
                        if (y < getElementId('hidNumLines').value) {
                            if (arrLines[y] == '') {
                                strAllPersText += 'Line ' + (y + 1) + ' - [LINE IS BLANK]<br />';
                            } else {
                                strAllPersText += 'Line ' + (y + 1) + ' - ' + arrLines[y] + '<br />';
                            }
                        }
                    }
                }
            }
        }
         
        if (intMode == 1) {
            strNewPersTextItem = '<u>Item #' + i + '</u><br />' + strNewPersTextItem;
            divReviewAllPers.innerHTML = strAllPersText + strNewPersTextItem;
            divReviewAllPers2.innerHTML = strAllPersText + strNewPersTextItem;
        } else {
            divReviewAllPers.innerHTML = strAllPersText;
            divReviewAllPers2.innerHTML = strAllPersText;
        }

Now, this all works fine and dandy in FF, but in IE there's a glitch. It appears to only display the content that was there the FIRST time the tooltip was activated. Once you look at the tooltip once, the content doesnt change. When tracing thru the code, I can clearly see the new content in divReviewAllPers.innerHTML, but it doesnt appear when I trigger the tooltip.
Another twist to this is that in IE, the content DOES update if you're updating a line that was there the first time you looked at the tooltip. ie: item 1, line 1 gets updated to say "test"..."test" will show in the dropdown, but the other items that were added & edited after the first tooltip activation still do not appear. Spooky??

Here is my tooltip html...
<center>
                                    <a href="#" id="lnkReviewAllPers" class="link-color">Click here to review all personalization text</a>
                                    </center>
                                    <rad:RadToolTip ID="RadToolTip7" Skin="Default" runat="server" TargetControlID="lnkReviewAllPers" ShowEvent="OnClick"
                                        IsClientID="true" RelativeTo="Element" Position="BottomCenter" Width="400px" Height="225px" Animation="Fade" ManualClose="true">
                                        <div id="divReviewAllPers" style="height:215px; overflow:auto;"></div>
                                    </rad:RadToolTip>

In the attached screenshot, you can see item #5 has been added, but it does not appear in the tooltip. Can someone advise why this might not be updating in IE?
Marin Bratanov
Telerik team
 answered on 26 Sep 2011
1 answer
91 views
On the demo page http://demos.telerik.com/aspnet-ajax/listview/examples/dataediting/manualediting/defaultcs.aspx the add button for the second listview should read "Add New Customer" not "Add New Product".

Regards

ROSCO
Mira
Telerik team
 answered on 26 Sep 2011
3 answers
143 views
Hi all,
Here http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/databindings/defaultcs.aspx I've read that I can bind different tables from data set to different levels. But I didn't found example with it and all my attempts failed.
My Db scheme: Category -> Item.
I want to show tree view like:

 cat1
 - item 1
 - item 2
 - item 3
 cat2
 - item 4

Right now I bind tree view from server side manually, but I want to use for example ObjectDataSource or SqlDataSource instead.

Plamen
Telerik team
 answered on 26 Sep 2011
1 answer
143 views
Hi,
I am setting my selectedrow style like this   
   <SelectedItemStyle BackColor="#FFE0C0" />

The problem is I am getting a gradient colour, not a single colour. Please help.
Pavlina
Telerik team
 answered on 26 Sep 2011
1 answer
178 views
I use telerik chart control in my asp.net application. Is there any way to change chart dynamically with clicking or dragging? If this is possible, I need to get new values of the chart. Thanks in advance.
Tsvetie
Telerik team
 answered on 26 Sep 2011
0 answers
79 views
Update: Problem solved.

Hello,

I have placed a grid into a slidingpane. When I have expanded the pane and I try to group by coluumns or reordering columns by drag&drop the columns, the box representing the column is not visible during dragging it into the group box or to antoher column position. Only wehn I move the mouse outer the pane the column box is visible under the mouse cursor. And if the slidingpane is pinned, all is working as expected. So I think it's a z-index problem. But how to solve it? 

We are using version 2011.2.712.35
The grid will be created programmatically.

Any suggestions?

Best regards,
Ralf
d-velop.de
Ralf
Top achievements
Rank 1
 asked on 26 Sep 2011
11 answers
346 views

I have written this jQuery code that allows a single RadEditor instance to be used to edit multiple different editable areas (editable bodies)  on the same page. It is very efficient and vastly improves page loading time but there are a few problems that I am unable to resolve and I hope you may be able to help.

To use the jQuery code, the markup on the page needs to be similar to this:

<div class="SKEditorWrapper">  
    <telerik:RadEditor using PageTop Toolbar goes here/> 
</div> 
 
<div id="BodyBlockPanel1" class="SKEditableBody">  
    <textarea name="BodyBlockHTML1" rows="2" cols="20" id="BodyBlockHTML1" class="SKEditableBodyText" style="display:none;">  
        This is editable body 1.  
    </textarea> 
</div> 
 
<div id="BodyBlockPanel2" class="SKEditableBody">  
    <textarea name="BodyBlockHTML2" rows="2" cols="20" id="BodyBlockHTML2" class="SKEditableBodyText" style="display:none;">  
        This is editable body 2.  
    </textarea> 
</div> 
 
<!-- ... and so on. We have 40 editable bodies on our page.--> 

The jQuery code hides the textareas and inserts a DIV after each of them, to render a WYSIWYG version of the markup. When the user clicks on the DIV, it is replaced with the RadEditor. The RadEditor is used with 'PageTop' toolbar and design mode only, to provide WYSIWYG in-place editing.

The jQuery code is as follows:

$(document).ready(function(){  
 
    var $bodyBlock;  
    var $editorBody;  
    var firstEdit = true;  
    var $prevEditableBody = null;  
      
    //Hide the RadEditor and its wrapper.  
    $('SKEditorWrapper').hide();  
    var $radEditor = $('div.RadEditor').hide();  
      
    var saveEditorContent = function(){  
        //Copy the content from the RadEditor back into the TextArea.  
        var editor = $find($radEditor.attr('id'));  
        var edContent = editor.get_html('true');  
        $prevEditableBody  
            .find('.SKEditableBodyText')  
            .val(edContent);  
    };  
 
    var moveEditorToBody = function(event){  
      
        var $editorPanel = $('.SKEditorWrapper');  
        var $editableBody = $(this);  
          
        //Switch off the mouse-over styling on all editable bodies on the page.  
        $('.SKEditableBody')  
            .removeClass('SKEditableBodyHighlight');  
 
        //Attach highlighter class and mousout handlers to transfer editor content  
        //to TextArea when the user clicks 'save'.              
        $editableBody  
            .addClass('SKEditableBodyHighlight')  
            .unbind('mouseenter mouseleave')  
            .mouseleave(saveEditorContent)  
            .blur(saveEditorContent);  
 
        //Remove the RadEditor from its current position in the DOM, replace  
        //it with a DIV to render the markup and copy the editor content into  
        //the TextArea ready for AJAX postback.              
        if (firstEdit){  
            firstEdit = false;  
            $editorPanel.remove();  
        }  
        else {  
            var editor = $find($radEditor.attr('id'));  
            var edContent = editor.get_html('true');  
            $('<div/>')  
                .addClass('SKEditableBodyBlockContent')  
                .html(edContent)  
                .replaceAll($editorPanel);  
            saveEditorContent();  
        }  
 
        //Insert the RadEditor into its new position in the DOM, i.e. in the  
        //editable body the user clicked on.  
        $editableBody.append($editorPanel);  
          
        //Find the DIV showing the rendered markup of this editable body and  
        //replace it with the RadEditor.  
        var editor = $find($radEditor.attr('id'));  
        $bodyBlock = $(event.target).closest('.SKEditableBodyBlockContent');  
        editor.set_html($bodyBlock.html());  
        var editorBody = document.all ? editor.get_document().body : editor.get_document();  
        $editorBody = $(editorBody);  
        $bodyBlock.remove();  
 
        //Show the RadEditor and its wrapper.  
        $editorPanel.show();  
        $radEditor.show();  
          
        //Delay a short time and then apply focus to editor to cause text cursor  
        //to be displayed in the RadEditor.  
        setTimeout(function(){  
            editor.setFocus();  
        },200);  
          
        //Prevent the click event from activating any links from anchor tags in the  
        //editable body.  
        event.preventDefault();  
          
        //Re-Attach click and hover handlers to the editable body that was being  
        //edited previously.  
        if ($prevEditableBody){  
            $prevEditableBody  
                .one('click', moveEditorToBody)  
                .unbind('mouseenter mouseleave')  
                .hover(function(){  
                    $(this).addClass('SKEditableBodyHighlight');  
                }, function(){  
                    $(this).removeClass('SKEditableBodyHighlight');  
            });  
        }  
        $prevEditableBody = $editableBody;  
 
    };  
      
    //Find the TextAreas for every editable body, hide them and insert a  
    //DIV to show their rendered markup.  
    $('.SKEditableBodyText').each(function(index){  
        $(this).hide();  
        $('<div/>')  
            .addClass('SKEditableBodyBlockContent')  
            .html($(this).val())  
            .insertAfter($(this));  
    });  
 
    //Make the editable bodies editable, using single RadEditor, when the user  
    //clicks them and attach mouse-overs to indicate which bodies are editable.  
    $('.SKEditableBody')  
        .one('click', moveEditorToBody)  
        .hover(function(){  
            $(this).addClass('SKEditableBodyHighlight');  
        }, function(){  
            $(this).removeClass('SKEditableBodyHighlight');  
        });  
 
}); 

The problems are:

  1. In IE/Chrome, after an editable body is clicked, the user has to click again before the text insert caret and toolbar will show. Is there a way to make these appear as soon as the user clicks on the editable DIV.
  2. In Firefox, the text insert caret never shows, no matter how many times the user clicks. Sadly, this makes it unusable in Firefox, although if the user enters text it does go into the correct position in the RadEditor. How can I cause the text insert caret to appear in Firefox?

I hope you can help, as this would be a very efficient solution to the problem of having multiple editable areas on a single page.

Misha
Top achievements
Rank 1
 answered on 26 Sep 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?