• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1956
  • Last Modified:

ASP.NET 3.5 DataGrid Edit using FCKEditor?

I am a total newbie to ASP.net, and finally figured out how to setup my datagrid to allow editing, and then finally figured out how to add an edit item template to create a text box to allow editing of a large 'text' column in our SQL database.

Now, I would like to use FCKEditor to edit that TEXT column.
See in the code snip below the <!--commented out--> textbox field - this works.
See the non commented FCKEditor field - when I click the UPDATE link in my datagrid, it simply writes a blank value back to the column in the database, even though, when clicking the EDIT link in the datagrid, the original value from the text column is populated into the FCKEditor control.

Anyone done this before?
<EditItemTemplate>
			<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" BasePath="~/fckeditor/" Value='<%# Bind("Description")%>' Width="400">
			</FCKeditorV2:FCKeditor>
                   <!--<asp:TextBox  Rows="5" columns="50" TextMode=MultiLine ID="TextBox1" runat="server" Text='<%# Bind("Description")%>'></asp:TextBox>-->
                   </EditItemTemplate></asp:TemplateField>

Open in new window

0
jn1480
Asked:
jn1480
  • 3
  • 2
1 Solution
 
prairiedogCommented:
What event handler are you using to update the record?
0
 
jn1480Author Commented:
Sorry prairiedog - total newbie - I am just using the default GridView control.
 I'm an old ASP3'er, so if you'd be willing to show me the manual - non-control way of doing this I'd be game!

/edit/default2.aspx page: 
 
    <p>
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="dsProducts">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowSelectButton="True" />
                <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" 
                    SortExpression="ID" />
                <asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item" />
                <asp:BoundField DataField="Description" Visible="False" HeaderText="Item" SortExpression="Description" />
                <asp:BoundField DataField="Price_Low" HeaderText="Price_Low" 
                    SortExpression="Price_Low" />
                <asp:BoundField DataField="Price_High" HeaderText="Price_High" 
                    SortExpression="Price_High" />
                <asp:BoundField DataField="Picture" HeaderText="Picture" 
                    SortExpression="Picture" />
                    <asp:TemplateField>
                    <ItemTemplate>
                    
                    </ItemTemplate>
                    <EditItemTemplate>
			<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" BasePath="~/fckeditor/" Value='<%# Bind("Description")%>' Width="400">
			</FCKeditorV2:FCKeditor>
                   <!--<asp:TextBox  Rows="5" columns="50" TextMode=MultiLine ID="TextBox1" runat="server" Text='<%# Bind("Description")%>'></asp:TextBox>-->
                   </EditItemTemplate></asp:TemplateField>
            </Columns>
        </asp:GridView>
    </p>
    <p>
        
        
        
        <asp:SqlDataSource ID="dsProducts" runat="server" 
            ConnectionString="<%$ ConnectionStrings:csServer %>" 
            SelectCommand="SELECT * FROM [Products]" 
            DeleteCommand="DELETE FROM [Products] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [Products] ([Item], [Description], [Price_Low], [Price_High], [Picture]) VALUES (@Item, @Description, @Price_Low, @Price_High, @Picture)" 
            UpdateCommand="UPDATE [Products] SET [Item] = @Item, [Description] = @Description, [Price_Low] = @Price_Low, [Price_High] = @Price_High, [Picture] = @Picture WHERE [ID] = @ID">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Byte" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Item" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="Price_Low" Type="Int32" />
                <asp:Parameter Name="Price_High" Type="Int32" />
                <asp:Parameter Name="Picture" Type="String" />
                <asp:Parameter Name="ID" Type="Byte" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Item" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="Price_Low" Type="Int32" />
                <asp:Parameter Name="Price_High" Type="Int32" />
                <asp:Parameter Name="Picture" Type="String" />
            </InsertParameters>
            </asp:SqlDataSource>
    </p>

Open in new window

0
 
prairiedogCommented:
1. Uncomment FCKeditor
2. Add this RowUpdating event handler in your code-behind:
 

Private Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
	Dim row As GridViewRow = Me.GridView1.Rows(e.RowIndex)
	Dim ftxtDescription As FredCK.FCKeditorV2.FCKeditor = CType(row.FindControl("FCKeditor1"), FredCK.FCKeditorV2.FCKeditor)
	Me.SqlDataSource1.UpdateParameters("Description").DefaultValue = ftxtDescription.Value
	Me.SqlDataSource1.Update()
	Me.GridView1.DataBind()
 
End Sub

Open in new window

0
 
jn1480Author Commented:
Thanks for the note prairiedog! I am still a bit too early on in my Beginning ASP.NET 3.5 book to fully understand what you are saying here. However, in my quick scanning of the upcoming chapters on database access/etc I do see some notes to this effect, so it gives me hope!
In the mean time, I got it to work using the apparently(?) more appropriate DetailsView control? (see code snippet)
That worked out just fine!

    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
        AllowPaging="True" AutoGenerateRows="False" DataKeyNames="ID" 
        DataSourceID="dsDatabase">
        
        <Fields>
            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" 
                SortExpression="ID" />
            <asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item" />
            <asp:TemplateField HeaderText="Description" SortExpression="Description">
                <EditItemTemplate>
                    <FCKeditorV2:FCKeditor ID="TextBox1" runat="server" BasePath="~/fckeditor/" Value='<%# Bind("Description") %>' Height="200" Width="500">
			</FCKeditorV2:FCKeditor>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Price_High" HeaderText="Price_High" 
                SortExpression="Price_High" />
            <asp:BoundField DataField="Price_Low" HeaderText="Price_Low" 
                SortExpression="Price_Low" />
            <asp:BoundField DataField="Picture" HeaderText="Picture" 
                SortExpression="Picture" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="dsDatabase" runat="server" 
        ConnectionString="<%$ ConnectionStrings:csLocal %>" 
        DeleteCommand="DELETE FROM [Products] WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [Products] ([Item], [Description], [Price_High], [Price_Low], [Picture]) VALUES (@Item, @Description, @Price_High, @Price_Low, @Picture)" 
        SelectCommand="SELECT [ID], [Item], [Description], [Price_High], [Price_Low], [Picture] FROM [Products]" 
        UpdateCommand="UPDATE [Products] SET [Item] = @Item, [Description] = @Description, [Price_High] = @Price_High, [Price_Low] = @Price_Low, [Picture] = @Picture WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Byte" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Item" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="Price_High" Type="Int32" />
            <asp:Parameter Name="Price_Low" Type="Int32" />
            <asp:Parameter Name="Picture" Type="String" />
            <asp:Parameter Name="ID" Type="Byte" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Item" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="Price_High" Type="Int32" />
            <asp:Parameter Name="Price_Low" Type="Int32" />
            <asp:Parameter Name="Picture" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>

Open in new window

0
 
prairiedogCommented:
Cool. Glad you got it worked out, though through a different approach from your original one.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now