Click here to Skip to main content

ancientrd asked:

Open original thread
Hi,
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 vb.net 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="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script type="text/javascript">
         var exportData = function (format) {
             App.FormatType.setValue(format);
             var store = App.GridPanel1.store;
             store.submitData(null, { isUpload: true });
         };
       
     </script>
  
</head>
<body>
    <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">
        <Store>
            <ext:Store id="Store1"  runat="server" RemoteSort="true"  buffered="true" PageSize="100" OnReadData="Store_ReadData"   önSubmitData="Store1_Submit"
>
                <Proxy>
                        <ext:PageProxy>
                            <Reader>
                                <ext:JsonReader Root="data" />
                            </Reader>
                        </ext:PageProxy>
                </Proxy>
                <Model>
                    <ext:Model  runat="server">
                        <Fields>
                            <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>
                        </Fields>
                    </ext:Model>
                </Model>
                <Sorters>
                        <ext:DataSorter Property="line_id" Direction="ASC" />
                </Sorters>
 
            </ext:Store>
        </Store>
        <ColumnModel  runat="server" >
            <Columns>
                <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">
                    <HeaderItems>
                         <ext:TextField ID="cod"  runat="server" EnableKeyEvents="true">
                                <Listeners>
                                    <KeyUp Handler="#{Store_ReadData}"   />                                                
                                </Listeners>
                            </ext:TextField>
                    </HeaderItems>
                </ext:Column>
                <ext:Column  runat="server" Text="tva" DataIndex="tva" Sortable="true"></ext:Column>
            </Columns>
        </ColumnModel>
        <view>
            <ext:GridView  runat="server" TrackOver="false" ></ext:GridView>
        </view>
        <SelectionModel>
            <ext:RowSelectionModel  runat="server" PruneRemoved="false" mode="Multi" ></ext:RowSelectionModel>
        </SelectionModel>
        <TopBar>
                <ext:Toolbar ID="Toolbar1"  runat="server">
                    <Items>
                        <ext:ToolbarFill ID="ToolbarFill1"  runat="server" />
                           
                        <ext:Button ID="Button1"  runat="server" Text="To XML" Icon="PageCode">
                            <Listeners>
                                <Click Handler="exportData('xml');" />
                            </Listeners>
                        </ext:Button>
                        
                        <ext:Button ID="Button2"  runat="server" Text="To Excel" Icon="PageExcel">
                            <Listeners>
                                <Click Handler="exportData('xls');" />
                            </Listeners>
                        </ext:Button>
                        
                        <ext:Button ID="Button3"  runat="server" Text="To CSV" Icon="PageAttach">
                            <Listeners>
                                <Click Handler="exportData('csv');" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
         <Features>
                        <ext:GridFilters   runat="server" ID="gridfilters1">
                            <Filters>
                              
                                <ext:StringFilter DataIndex="cod" />
                                <ext:listfilter DataIndex="tva" Options="0,9,24" />
                            </Filters>
                        </ext:GridFilters>
                    </Features>
 
    </ext:GridPanel>
        <ext:Label ID="Label2"  runat="server" />
    </form>
</body>
</html>
and the vb.net
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)
        Try
            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 "
                        Else
                            ffiltru = ffiltru + "("
                            For i = 0 To fcond.List.Count - 1
                                ffiltru = ffiltru + fcol.ToString + "=" + fcond.List.Item(i).ToString + " or "
                            Next
                            ffiltru = ffiltru.Substring(0, ffiltru.Length - 4) + ") and "
                        End If
                    End If
                Next
            End If
            If ffiltru.Length > 6 Then
                ffiltru = ffiltru.Substring(0, ffiltru.Length - 4)
            Else
                ffiltru = ffiltru + "1=1"
            End If
            Dim zzz As String = e.Parameters("cod")
            If Not String.IsNullOrEmpty(zzz) Then
                MsgBox(zzz)
            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
        Me.Response.Clear()
        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"
                Me.Response.Write(strXml)
                Exit Select
            Case "xls"
                Me.Response.ContentType = "application/vnd.ms-excel"
                Me.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls")
                Dim xtExcel As New XslCompiledTransform()
                xtExcel.Load(Server.MapPath("/test/Excel.xsl"))
                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.Load(Server.MapPath("/test/Csv.xsl"))
                xtCsv.Transform(xml, Nothing, Response.OutputStream)
                Exit Select
        End Select
 
        Me.Response.[End]()
    End Sub
    Public Function querydbdata(ByVal xxx As String) As DataTable
        Dim mydatatable As New DataTable
        Try
            myconnection = New MySqlConnection(myconnstr)
            Dim myadapter As New MySqlDataAdapter(xxx, myconnection)
            myconnection.Open()
            myadapter.Fill(mydatatable)
            myconnection.Dispose()
        Catch ex As Exception
            MsgBox(ex.ToString)
            ' 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 = ""
        Try
            Dim myconnection As New MySqlConnection(myconnstr)
            Dim mycmd As New MySqlCommand(xxx, myconnection)
            mycmd.Connection.Open()
            raspuns = mycmd.ExecuteScalar()
            mycmd.Connection.Dispose()
        Catch ex As Exception
            raspuns = "Eroare : " + ex.ToString
        End Try
        Return raspuns
    End Function
End Class
Tags: VB.NET, ASP.NET, Gridview, search, Ext.Net

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
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