Cannot get text value from editor in gridview

Last post 04-23-2009, 5:00 AM by Kenneth. 1 replies.
Sort Posts: Previous Next
  •  04-22-2009, 5:16 PM 51399

    Cannot get text value from editor in gridview

    Hello,
     
    I have the editor embedded in a gridview and it works great.
     
    I just want to preview the live content before I submit it to the database.
     
    The editor doesn't use the javascript in the preview mode. Below is some code that I want to use to show the content of the editor in a label box that is not embedded in the gridview.
     

    Protected Sub btnupdatepreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupdatepreview.Click

     

    Dim txt1 As CuteEditor.Editor = GridView1.FindControl("txtmenu")

    lblpreview.Text = txt1.Text

    End Sub

     
    Is this the correct way of doing it ?
     
     
     
     
  •  04-23-2009, 5:00 AM 51413 in reply to 51399

    Re: Cannot get text value from editor in gridview

    Hi mstrsftwr,
     
    Try this example please:
     
    ---------------------------------------------------->

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Register Namespace="CuteEditor" Assembly="CuteEditor" TagPrefix="CE" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
        Private Function CreateDataSource() As ICollection
            Dim dt As New DataTable()
            Dim dr As DataRow
            dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
            For i As Integer = 0 To 1
                dr = dt.NewRow()
           
                dr(0) = i
                dt.Rows.Add(dr)
            Next
            Dim dv As New DataView(dt)
            Return dv
        End Function
        Private Sub Page_Load(ByVal sender As [Object], ByVal e As EventArgs)
            If Not IsPostBack Then
                GridView1.DataSource = CreateDataSource()
                GridView1.DataBind()
           
            End If
        End Sub
        Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
            If e.CommandName = "show" Then
                Dim show As Button = DirectCast(e.CommandSource, Button)
                Dim row As GridViewRow = DirectCast(show.Parent.Parent, GridViewRow)
                Dim editor1 As CuteEditor.Editor = DirectCast(row.FindControl("editor1"), CuteEditor.Editor)
                label1.Text = editor1.Text
            End If
        End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <CE:Editor ID="editor1" runat="server">
                            </CE:Editor>
                            <asp:Button ID="button1" runat="server" Text="show" CommandName="show" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="IntegerValue" />
                </Columns>
            </asp:GridView>
            <asp:Label ID="label1" runat="server"></asp:Label>
        </form>
    </body>
    </html>
    ---------------------------------------------------->
     
     
    Regards,
     
    ken
View as RSS news feed in XML