function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JoanJoan 

use GridView in search

Hello
 
After I do the search as following:
 
binding.search("find {test}in ALL FIELDS returning solution(SolutionName, SolutionNote)")
 
How can I use GridView so that I can display limite records each page?
 
Thanks,
 
 
 
DevAngelDevAngel
You can loop through your results creating a dataset as you go.  Create a two column datatable, add it to the new dataset.  Create a new row from the datatable for each record using the values for the new row.  Add the row to the table.

Now you can set the datasource of your grid to the dataset.
JoanJoan
Thanks for reply, that's what I was trying to do, but when I use

Dim dstAccounts As New DataSet,

I got error DataSet is not defined, any class I need to import?

Thanks,

JoanJoan

any examples in vb.net?

Thanks,

nomisnomis
Hi Joan,
 
JoanJoan

Thanks for reply, but when I try this coding, I got error message: Array is a type and cannot be used as expression

Following is my original coding before I got your reply:

<asp:DataGrid id="MySolutions" AutoGenerateColumns="False" AllowPaging="true" AllowSorting="true"

Width="100%" DataKeyField="SolutionName" runat="server">

<HeaderStyle BackColor="#66CCFF" Font-Names="Arial" Font-Size="10" Font-Bold="True"/>

<ItemStyle BackColor="#FFFFFF" Font-Names="Arial" Font-Size="9"/>

<Columns>

<asp:TemplateColumn HeaderText="Solution Name">

<ItemTemplate>

<asp:Label ID="Label1" Text='<%# DataBinder.Eval(Container.DataItem, "SolutionName")%>' runat="server"/>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

<Columns>

<asp:TemplateColumn HeaderText="Solution Note">

<ItemTemplate>

<asp:Label ID="Label1" Text='<%# DataBinder.Eval(Container.DataItem, "SolutionNote")%>' runat="server"/>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

</asp:DataGrid>

codbehind:

Try

mySearchResult = sfdc.search("find {" & SolutionSearch.Text & "}in ALL FIELDS returning solution(SolutionName, SolutionNote, IsPublished, Related_To__c, Publish_to_public__c)")

Dim records() As SearchRecord = mySearchResult.searchRecords

Dim Solutions As System.Collections.ArrayList = New System.Collections.ArrayList

If Not mySearchResult.searchRecords Is Nothing Then

For i As Integer = 0 To records.Length - 1

Dim record As sObject = records(i).record

If record.GetType Is GetType(Solution) Then

Solutions.Add(record)

End If

Next

If (Solutions.Count > 0) Then

Dim myDataset As DataSet = CreateDataSet()

For i As Integer = 0 To Solutions.Count - 1

Dim dstSolutions As New DataSet

MySolutions.DataSource = mySearchResult.searchRecords

MySolutions.DataBind()

Next

Else

lblsolutions.Text = "No records found<hr>"

End If

Else

lblsolutions.Text = "No records found<hr>"

End If

Catch ex As Exception

Response.Write(ex.Message.ToString & "<hr>")

End Try

After run, I got error: DataBinding: 'sfdcSandbox.SearchRecord' does not contain a property with the name 'SolutionName'.

any idea? Thanks,

DevAngelDevAngel
An arraylist is indexable only by ordinal, not by name. Seems like you should be using a different kind of collection.

One important question, are you using the Partner WSDL or the Enterprise WSDL?


DevAngelDevAngel
The samples below are for a windows form application, but the concepts apply to ASP.NET as well.
 
 
Code:
Public Class Form1

#Region "Partner wsdl implementation"
    Dim binding As sfdc.SforceService = New sfdc.SforceService()

    Private Sub loginPartner()
        Dim lr As sfdc.LoginResult = binding.login("user@email.com", "secret")
        binding.SessionHeaderValue = New sfdc.SessionHeader()
        binding.SessionHeaderValue.sessionId = lr.sessionId
        binding.Url = lr.serverUrl
    End Sub
    Private Sub LoadSearchGridPartner(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        loginPartner()
        Dim searchResult As sfdc.SearchResult = binding.search("FIND {Digital*} IN NAME FIELDS RETURNING Account (Type, Website)")
        Dim searchRecords() As sfdc.SearchRecord = searchResult.searchRecords
        Dim ds As DataSet
        If searchRecords.Length > 0 Then
            ds = New DataSet("searchResult")
            Dim dt As New DataTable("searchTable")
            dt.Columns.Add(New DataColumn("Type"))
            dt.Columns.Add(New DataColumn("Website"))
            For i As Integer = 0 To searchRecords.Length - 1
                Dim record As sfdc.sObject = searchRecords(i).record
                Dim dr As DataRow = dt.NewRow()
                dr("Type") = getSObjectFieldValue("Type", record)
                dr("Website") = getSObjectFieldValue("Website", record)
                dt.Rows.Add(dr)
            Next
            ds.Tables.Add(dt)
            Me.DataGridView1.DataSource = ds
            Me.DataGridView1.DataMember = "searchTable"
        End If
    End Sub

    Private Function getSObjectFieldValue(ByVal fieldName As String, ByVal record As sfdc.sObject) As String
        For i As Integer = 0 To record.Any.Length - 1
            Dim fld As Xml.XmlElement = record.Any(i)
            If fld.LocalName.ToLower().Equals(fieldName.ToLower()) Then
                Return fld.InnerText
            End If
        Next
        Return String.Empty

    End Function
#End Region

#Region "Enterprise wsdl implementation"
    Dim bindingE As sfdcE.SforceService = New sfdcE.SforceService()

    Private Sub loginEnterprise()
        Dim lr As sfdcE.LoginResult = bindingE.login("user@email.com", "secret")
        bindingE.SessionHeaderValue = New sfdcE.SessionHeader()
        bindingE.SessionHeaderValue.sessionId = lr.sessionId
        bindingE.Url = lr.serverUrl
    End Sub

    Private Sub LoadSearchGridEnterprise(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        loginEnterprise()
        Dim searchResult As sfdcE.SearchResult = bindingE.search("FIND {Digital*} IN NAME FIELDS RETURNING Account (Type, Website)")
        Dim searchRecords() As sfdcE.SearchRecord = searchResult.searchRecords
        Dim ds As DataSet
        If searchRecords.Length > 0 Then
            ds = New DataSet("searchResult")
            Dim dt As New DataTable("searchTable")
            dt.Columns.Add(New DataColumn("Type"))
            dt.Columns.Add(New DataColumn("Website"))
            For i As Integer = 0 To searchRecords.Length - 1
                Dim record As sfdcE.Account = searchRecords(i).record
                Dim dr As DataRow = dt.NewRow()
                dr("Type") = record.Type
                dr("Website") = record.Website
                dt.Rows.Add(dr)
            Next
            ds.Tables.Add(dt)
            Me.DataGridView1.DataSource = ds
            Me.DataGridView1.DataMember = "searchTable"
        End If
    End Sub
#End Region
End Class

 
JoanJoan

Hi dave,

Thank you so much for your quickly reply, we are using  Enterprise WSDL, I'll try your coding and let you know if it works or not

JoanJoan
Thanks Dave
It works fine now. If anyone needs web application for this function, please post message here, I'm happen to share it
JoanJoan

Hi There,

I'm going to create windows appication instaed of web application using Microsoft Visual Studio 2005, I know after create windows application, I need to create  exe file to execute it, but I don't know how to create exe file in MS VS 2005, anyone can tell me?

Thanks

DevAngelDevAngel
When you build or debug the project (f5) an exe is created.  Check the build / config properties to find out where.
JoanJoan
Thanks,