Click here to Skip to main content
13,254,077 members (60,492 online)
Rate this:
Please Sign up or sign in to vote.
I want to add a textbox in the header of a column and when keypress event on it is fired i need to use a function (not java) from my form. It must pass the textbox.text value to that fuction.I need it to make a search in the gridview.
I will want to add it in the filter and if i can take the event as StoreReadDataEventArgs . I BOLDED the code in where i need to catch the parameter.
How can i do that ? Thank you.
My code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
     <script type="text/javascript">
         var exportData = function (format) {
             var store =;
             store.submitData(null, { isUpload: true });
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1"  runat="server" />
         <ext:Hidden ID="FormatType"  runat="server" />
    <ext:GridPanel ID="GridPanel1"  runat="server" Height="400" Title="TESTE">
            <ext:Store id="Store1"  runat="server" RemoteSort="true"  buffered="true" PageSize="100" OnReadData="Store_ReadData"   önSubmitData="Store1_Submit"
                                <ext:JsonReader Root="data" />
                    <ext:Model  runat="server">
                            <ext:ModelField Name="line_id" Mapping="line_id"></ext:ModelField>
                            <ext:ModelField Name="cod" Mapping="cod"></ext:ModelField>
                             <ext:ModelField Name="tva" Mapping="tva"></ext:ModelField>
                        <ext:DataSorter Property="line_id" Direction="ASC" />
        <ColumnModel  runat="server" >
                <ext:RowNumbererColumn  runat="server" Width="50" Sortable="false"></ext:RowNumbererColumn>
                <ext:Column  runat="server" Text="line_id" DataIndex="line_id" Sortable="true"></ext:Column>
                <ext:Column  runat="server" Text="cod" DataIndex="cod" Sortable="true">
                         <ext:TextField ID="cod"  runat="server" EnableKeyEvents="true">
                                    <KeyUp Handler="#{Store_ReadData}"   />                                                
                <ext:Column  runat="server" Text="tva" DataIndex="tva" Sortable="true"></ext:Column>
            <ext:GridView  runat="server" TrackOver="false" ></ext:GridView>
            <ext:RowSelectionModel  runat="server" PruneRemoved="false" mode="Multi" ></ext:RowSelectionModel>
                <ext:Toolbar ID="Toolbar1"  runat="server">
                        <ext:ToolbarFill ID="ToolbarFill1"  runat="server" />
                        <ext:Button ID="Button1"  runat="server" Text="To XML" Icon="PageCode">
                                <Click Handler="exportData('xml');" />
                        <ext:Button ID="Button2"  runat="server" Text="To Excel" Icon="PageExcel">
                                <Click Handler="exportData('xls');" />
                        <ext:Button ID="Button3"  runat="server" Text="To CSV" Icon="PageAttach">
                                <Click Handler="exportData('csv');" />
                        <ext:GridFilters   runat="server" ID="gridfilters1">
                                <ext:StringFilter DataIndex="cod" />
                                <ext:listfilter DataIndex="tva" Options="0,9,24" />
        <ext:Label ID="Label2"  runat="server" />

and the
Imports MySql.Data.MySqlClient
Imports Ext.Net
Imports System.Xml.Xsl
Imports System.Xml
Public Class _Default
    Inherits System.Web.UI.Page
    Public myconnstr As String = "server=81.***.202.***;" _
                                     & "port=3306;" _
                                     & "uid=***;" _
                                     & "pwd=***;" _
                                     & "database=liviuivil;" _
                                     & "Convert Zero Datetime=True;"
    Public myreader As MySqlDataReader
    Public myconnection As MySqlConnection
    Public mycmd As MySqlCommand
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Protected Sub Store_ReadData(sender As Object, e As StoreReadDataEventArgs)
            Dim store As Store = DirectCast(sender, Store)
            Dim start As Integer = e.Start
            Dim limit As Integer = e.Limit
            Dim coloana As String = e.Sort(0).Property.ToString
            Dim tipsort As String = e.Sort(0).Direction.ToString
            Dim sfilters As String = e.Parameters(gridfilters1.ParamPrefix)
            Dim ffiltru As String = "WHERE "
            If Not String.IsNullOrEmpty(sfilters) Then
                Dim ffc As New FilterConditions(sfilters)
                For Each fcond As FilterCondition In ffc.Conditions
                    Dim fcol As String = fcond.Field
                    Dim ftype As FilterType = fcond.Type
                    If fcond.Type = FilterType.String Then
                        ffiltru = ffiltru + fcol.ToString + "=" + fcond.Value(Of String).ToString + " and "
                    End If
                    If fcond.Type = FilterType.List Then
                        If fcond.List.Count = 1 Then
                            ffiltru = ffiltru + "(" + fcol.ToString + "=" + fcond.List.Item(0).ToString + ")" + " and "
                            ffiltru = ffiltru + "("
                            For i = 0 To fcond.List.Count - 1
                                ffiltru = ffiltru + fcol.ToString + "=" + fcond.List.Item(i).ToString + " or "
                            ffiltru = ffiltru.Substring(0, ffiltru.Length - 4) + ") and "
                        End If
                    End If
            End If
            If ffiltru.Length > 6 Then
                ffiltru = ffiltru.Substring(0, ffiltru.Length - 4)
                ffiltru = ffiltru + "1=1"
            End If
            Dim zzz As String = e.Parameters("cod")
            If Not String.IsNullOrEmpty(zzz) Then
            End If           
            Dim hhh As String = "SELECT line_id,cod,tva FROM local_stoc " + ffiltru + " ORDER BY " + coloana + " " + tipsort + " LIMIT " + start.ToString + "," + limit.ToString
            Label2.Text = hhh
            store.Data = querydbdata("SELECT line_id,cod,tva FROM local_stoc " + ffiltru + " ORDER BY " + coloana + " " + tipsort + " LIMIT " + start.ToString + "," + limit.ToString)
            e.Total = querydb("SELECT COUNT(*) FROM local_stoc " + ffiltru)
        Catch ex As Exception
        End Try
    End Sub



    Protected Sub Store1_Submit(sender As Object, e As StoreSubmitDataEventArgs)
        Dim format As String = Me.FormatType.Value.ToString()
        Dim xml As XmlNode = e.Xml
        Select Case format
            Case "xml"
                Dim strXml As String = xml.OuterXml
                Me.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xml")
                Me.Response.AddHeader("Content-Length", strXml.Length.ToString())
                Me.Response.ContentType = "application/xml"
                Exit Select
            Case "xls"
                Me.Response.ContentType = "application/"
                Me.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls")
                Dim xtExcel As New XslCompiledTransform()
                xtExcel.Transform(xml, Nothing, Response.OutputStream)
                Exit Select
            Case "csv"
                Me.Response.ContentType = "application/octet-stream"
                Me.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.csv")
                Dim xtCsv As New XslCompiledTransform()
                xtCsv.Transform(xml, Nothing, Response.OutputStream)
                Exit Select
        End Select
    End Sub
    Public Function querydbdata(ByVal xxx As String) As DataTable
        Dim mydatatable As New DataTable
            myconnection = New MySqlConnection(myconnstr)
            Dim myadapter As New MySqlDataAdapter(xxx, myconnection)
        Catch ex As Exception
            ' mydatatable.Columns.Add()
            ' mydatatable.Rows.Add()
            ' mydatatable.Rows(0)(0) = ex.Message.ToString
        End Try
        Return mydatatable
    End Function
    Public Function querydb(ByVal xxx As String) As String
        Dim raspuns As String = ""
            Dim myconnection As New MySqlConnection(myconnstr)
            Dim mycmd As New MySqlCommand(xxx, myconnection)
            raspuns = mycmd.ExecuteScalar()
        Catch ex As Exception
            raspuns = "Eroare : " + ex.ToString
        End Try
        Return raspuns
    End Function
End Class
Posted 27-Oct-12 3:44am
Frank Reidar Haugen 27-Oct-12 17:21pm
I'd love to see more comments, to make everything more readable; you probably see a lot more order in all this then I do, just looking at it.

As I understand it you want to "add" a textbox element during "runtime". Then why don't you just have it "invisible" until you change it's attributes to show it, and move it to the desired location when appropriate?
ancientrd 29-Oct-12 6:46am
:) i already render the textbox on the column header . i just need a way to catch it's keypress event , since is in the header template.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I changed the code to :
         <keyup onevent="add_like"></keyup>

Works like a charm now :))) can have filters + sorting + search in the gridview template :))))))))))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 29 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100