Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET 3.5 DataGrid Edit using FCKEditor?

Posted on 2008-11-19
5
Medium Priority
?
1,951 Views
Last Modified: 2012-05-05
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
Comment
Question by:jn1480
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 23004701
What event handler are you using to update the record?
0
 

Author Comment

by:jn1480
ID: 23004733
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
 
LVL 22

Accepted Solution

by:
prairiedog earned 800 total points
ID: 23005255
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
 

Author Comment

by:jn1480
ID: 23133722
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
 
LVL 22

Expert Comment

by:prairiedog
ID: 23133761
Cool. Glad you got it worked out, though through a different approach from your original one.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question