Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Gridview VB.NET search , +
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
Posted 27-Oct-12 3:44am
Comments
Frank Reidar Haugen at 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 at 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
good
Please Sign up or sign in to vote.

Solution 1

I changed the code to :
  <directevents>
           <keyup onevent="add_like"></keyup>
     </directevents>
Works like a charm now Smile | :) )) can have filters + sorting + search in the gridview template Smile | :) )))))))))
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 165
2 PIEBALDconsult 150
3 BillWoodruff 148
4 DamithSL 140
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 29 Oct 2012
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