This is a migrated thread and some comments may be shown as answers.

Access EditItemTemplate and apply Radspell

3 Answers 112 Views
Spell
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 06 Jul 2011, 07:52 PM

 

Hi All,

First post as I've struggled to figure this one out, new to Telerik and .Net so possibly a bad combination!

I've taken the following snippet from the demo for using radspell with radgrid, but the problem I appear to have is that I also want to spellcheck the edit control of gridtemplatecolumns as well as gridboundcolumns. I'm trying to figure out how to just access the edit section of the gridtemplatecolumn (my attempt is currently commented out and marked PROBLEM BIT) the trouble is that whilst it works to a degree it appears to be duplicating a whole load of information when the spell checker pops up (there also appears to be a lot of white space in 'not in dictionary' area.

In short, it's misbehaving but I'm sure it must be something obvious I'm doing.

please help! I've been on this for 10 hours straight (as a learner!) and I'm fed up with it now!

Thanks in advance,

Dave


 

 

foreach (GridColumn column in editedItem.OwnerTableView.RenderColumns)

 

{

 

if (column is IGridEditableColumn && column.IsEditable)

 

{

 

IGridColumnEditor editor = editMan.GetColumnEditor(column as IGridEditableColumn);

 

 

if (editor is GridTextBoxColumnEditor)

 

{

 

string editorID = (editor as GridTextBoxColumnEditor).TextBoxControl.ClientID;

 

controlsToCheck.Push(editorID);

index++;

}

 

/*
PROBLEM BIT
if (editor is GridTemplateColumnEditor)

 

{

string editorID = (editor as GridTemplateColumnEditor).ContainerControl.ClientID;

controlsToCheck.Push(editorID);

index++;

}*/

 

 

 

}

 

}

RadSpell1.ControlsToCheck =

new string[index];

 

 

while (controlsToCheck.Count > 0)

 

{

RadSpell1.ControlsToCheck.SetValue(controlsToCheck.Pop(), controlsToCheck.Count);

}

RadSpell1.IsClientID =

true;

 

 


 

 

<telerik:GridTemplateColumn HeaderText="KSP/Benefit 1" UniqueName="cnpb_benefit1" DataField="cnpb_benefit1" Visible="False" FilterControlAltText="Filter cnpb_benefit1 column">

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

<asp:Label ID="lblcnpb_benefit1" runat="server" Text='<%# TrimDescription(Eval("cnpb_benefit1") as string) %>' />

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

<EditItemTemplate>

 

 

 

 

 

<telerik:RadTextBox ID="txbcnpb_benefit1" Width="450px" runat="server" TextMode="MultiLine"

 

 

 

 

 

Text='<%# Bind("cnpb_benefit1") %>' Height="90px" MaxLength="500" />

 

 

 

 

 

</EditItemTemplate>

 

 

 

 

 

<ItemStyle VerticalAlign="Top" />

 

 

 

 

 

</telerik:GridTemplateColumn>

 

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 11 Jul 2011, 01:27 PM
Hi Dave,

If the editor is placed in ItemDataBound of RadGrid then you can get a reference using the following code:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
    {
        GridEditableItem edititem = e.Item as GridEditableItem;
        RadEditor radEditor = e.Item.FindControl("RadEditor1") as RadEditor;
    }
}

Using a similar approach you can access the editor in the EditItemTemplate of RadGrid and obtain its Id.

Best regards,
Rumen
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Dave
Top achievements
Rank 1
answered on 12 Jul 2011, 12:27 PM
Hi Rumen,

Thanks for coming back to me, unfortunately your response has left me a little confused. I'll try to clarify, which may help you understand the situation a little clearer (and understand my knowledge or lack thereof).

The event this is being called in is the Item Created event (as per the spell check example on the Telerik website).
I'm looping through each of the columns in the editedItem.OwnerTableView.RenderColumns collection
The following (from the example) correctly picks up the contents of each of the gridboundcolumns

 

if (editor is GridTextBoxColumnEditor)

 

{

 

string editorID = (editor as GridTextBoxColumnEditor).TextBoxControl.ClientID;

 

controlsToCheck.Push(editorID);

index++;

}

But my edit form also has gridtemplatecolumns, as per below:

 

 

<telerik:GridTemplateColumn HeaderText="KSP/Benefit 1" UniqueName="cnpb_benefit1" DataField="cnpb_benefit1" Visible="False" FilterControlAltText="Filter cnpb_benefit1 column">

 

 

 

<ItemTemplate>

 

 

<asp:Label ID="lblcnpb_benefit1" runat="server" Text='<%# TrimDescription(Eval("cnpb_benefit1") as string) %>' />

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<telerik:RadTextBox ID="txbcnpb_benefit1" Width="450px" runat="server" TextMode="MultiLine" Text='<%# Bind("cnpb_benefit1") %>' Height="90px" MaxLength="500" />

 

 

</EditItemTemplate>

 

 

<ItemStyle VerticalAlign="Top" />

 

 

</telerik:GridTemplateColumn>

I'm trying to access the EditItem Template only but my code in the original example appears to pick up the content of the itemtemplate and the edititem template for each. It then has some very peculiar behavior when it shows this in the spell check form.

Whilst I understand the code in your example, I'm not sure how to translate it to fit my requirement as it's called from a different event (and hence the e argument is different) and I'm not sure how I can cast the content of a column from a OwnerTableView.RenderColumns  collection to a Radeditor (and even then, as it is looping through the collection, I couldn't use the findcontrol function to source the control as there are approximately 20 gridtemplate columns on my forms with different names.

In short, if you are able to set me in the right direction with the starting point being the telerik example here: http://www.telerik.com.ag/help/aspnet-ajax/grid-spell-check-editors.html

I simply require a snippet of code that can be put in the OwnerTableView.RenderColumns 'for each' loop which will extract, and add the EditItemTemplate element of each gridtemplatecolumn to the controls to check stack so that the text content gets included in the spellcheck.

I appreciate your help to date but I cannot figure out how to use it in this example. Hopefully the information above clarifies what I'm trying to achieve and you are able to give me a little more guidance. My apologies, I'm still a novice with both .net and Telerik, I'm finding some things incredibly logical and easy and others (like this, which I feel should be simple) incredibly difficult to figure out!

Thanks in advance for your help, look forward to hearing back from you.

Dave

 

0
Daniel
Telerik team
answered on 13 Jul 2011, 03:38 PM
Hello Dave,

Please try to add the following condition to your existing project:
...
else if (editor is GridTemplateColumnEditor)
{
    GridTemplateColumnEditor tcEditor = editor as GridTemplateColumnEditor;
    string editorID = (editor as GridTemplateColumnEditor).ContainerControl.Controls[1].ClientID;
    controlsToCheck.Push(editorID);
    index++;
}

This above code assumes that you have an item template like this:
<EditItemTemplate>
    <telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Bind("ProductName") %>' Height="300px">
    </telerik:RadEditor>
</EditItemTemplate>

Also, I attached a modified version of the online demo to show this approach in action.

Best regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Spell
Asked by
Dave
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Dave
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or