FCKeditor in GridView control: insert/update

Last post 05-09-2008 4:22 PM by GDB. 3 replies.

Sort Posts:

  • FCKeditor in GridView control: insert/update

    05-03-2008, 11:11 AM
    • Loading...
    • GDB
    • Joined on 01-05-2006, 9:35 PM
    • Posts 99

    I'm trying to integrate FCKeditor into a GridView control in order to insert/edit new records. I will eventually use DetailsView for inserting/editing but for now I just need to modify some existing code.

    The existing GridView code:

    <asp:TemplateField HeaderText="Product Description" SortExpression="Description">

    <ItemTemplate>

    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="descriptionTextBox" runat="server" Text='<%# Bind("Description") %>'

    Height="100px" Width="97%" CssClass="GridEditingRow" TextMode="MultiLine" />

    </EditItemTemplate>

    </asp:TemplateField>

    Code behind:

    string description = ((TextBox)grid.Rows[e.RowIndex].FindControl("descriptionTextBox")).Text;

     

    My new GridView code:

    </asp:TemplateField>

    <asp:TemplateField HeaderText="Item Description" SortExpression="Description">

    <ItemTemplate>

    <asp:Label ID="LabelDescription" runat="server" Text='<%# Eval("Description") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate>

    <FCKeditorV2:FCKeditor ID="FCKeDescription" Height="100" ToolbarSet="Title" Value='<%# Bind("Description") %>'

    runat="server">

    </FCKeditorV2:FCKeditor>

    </EditItemTemplate>

    </asp:TemplateField>

    My attempts at code behind:

    Attempt #1:

    string description = (grid.Rows[e.RowIndex].FindControl("FCKeDescription.")).ToString();

    Attempt #1 result: simply inserts "FredCK.FCKeditorV2.FCKeditor" into the description field in the database

    Attempt #2:

    string description = (grid.Rows[e.RowIndex].FindControl("FCKeDescription.Value")).ToString();

    Attempt #2 result: throws the error "System.NullReferenceException: Object reference not set to an instance of an object.

    Attempt #3:

    string description = (grid.Rows[e.RowIndex].FindControl(FCKeDescription.Value)).ToString();

    Attempt #1 result: thows the error "The name 'FCKeDescription' does not exist in the current context"

    Attempt #4:

    string fCKeDescription = FCKeDescription.Value.ToString();

    protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

    string description = (grid.Rows[e.RowIndex].FindControl("fCKeDescription")).ToString();

    }

    Attempt #4 result: thows the error "The name 'FCKeDescription' does not exist in the current context"

     

  • Re: FCKeditor in GridView control: insert/update

    05-06-2008, 4:05 AM

    Hi GDB,

    Try this:

    string description = ((FCKeditor)grid.Rows[e.RowIndex].Cells[index].FindControl("FCKeDescription")).Value;   //Set index for cell.

    Thanks,

    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: FCKeditor in GridView control: insert/update

    05-06-2008, 3:54 PM
    Answer
    • Loading...
    • GDB
    • Joined on 01-05-2006, 9:35 PM
    • Posts 99

    Thanks Qin,

    I couldn't get this to work. I've decided to work first on a DetailsView as a better control for using FCKeditor for creating and maintaining the records. Once I get FCKeditor working in that control I'm going to come back to the GridView problem to work it through so this thread end up with an answer.

    Gary

  • Re: FCKeditor in GridView control: insert/update

    05-09-2008, 4:22 PM
    Answer
    • Loading...
    • GDB
    • Joined on 01-05-2006, 9:35 PM
    • Posts 99

    I've succeeded in getting this to work.

    Set and note the editor id in the aspx markup, e.g.  ID="descriptionFcke"  in the markup below:

    <EditItemTemplate>

    <FCKeditorV2:FCKeditor ID="descriptionFcke" Height="150" Value='<%# Bind("Description") %>'

    runat="server">

    </FCKeditorV2:FCKeditor>

    </EditItemTemplate>

    Next create a reference in the code behind:

    using FredCK.FCKeditorV2;

    Now you can replace the text box code with the FCKe code as below:

    Replace:

     string description = ((TextBox)grid.Rows[e.RowIndex].FindControl("descriptionTextBox")).Text;

    With This:

    string description = ((FCKeditor)grid.Rows[e.RowIndex].FindControl("descriptionFcke")).Value;

     On a tangentially related note, it used to be the case that you needed to set ValidateRequest="false" in the page directive to avoid the "A potentially dangerous Request.Form value was detected from the client ... " error. This was unsafe and is no longer necessary in Version 2.6

Page 1 of 1 (4 items)