I have a grid that I bind in the code behind. Whenever I click the export button, it just removes the paging and displays all 6000 records on one page, and doesn't export anything. Any ideas why? Here's the aspx and code behind
<%@ Page Title="" Language="VB" MasterPageFile="~/Main.master" AutoEventWireup="false"
CodeFile="CustomerList.aspx.vb" Inherits="Customers_CustomerList" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"head"
Runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"mainContentPlaceHolder"
Runat
=
"Server"
>
<
telerik:RadFormDecorator
ID
=
"decorator"
Skin
=
"Default"
DecoratedControls
=
"Buttons"
runat
=
"server"
/>
<
telerik:RadTextBox
ID
=
"searchInput"
runat
=
"server"
>
</
telerik:RadTextBox
>
<
asp:Button
ID
=
"searchGrid"
runat
=
"server"
Text
=
"Search"
/>
<
asp:Button
ID
=
"Reset"
runat
=
"server"
Text
=
"reset"
/>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
GridLines
=
"None"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"false"
PageSize
=
"50"
Height
=
"400px"
>
<
MasterTableView
DataKeyNames
=
"customerid"
AutoGenerateColumns
=
"false"
>
<
RowIndicatorColumn
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
AllowSorting
=
"false"
DataField
=
"Edit"
HeaderText="<span
style
=
'visibility: hidden;'
>a</
span
>">
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
HeaderText
=
"FirstName"
SortExpression
=
"FirstName"
UniqueName
=
"FirstName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"LastName"
HeaderText
=
"LastName"
SortExpression
=
"LastName"
UniqueName
=
"LastName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Business Name"
HeaderText
=
"Business Name"
SortExpression
=
"Business Name"
UniqueName
=
"Business Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"State"
HeaderText
=
"State"
SortExpression
=
"State"
UniqueName
=
"State"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Zip"
HeaderText
=
"Zip"
SortExpression
=
"Zip"
UniqueName
=
"Zip"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Address"
HeaderText
=
"Address"
SortExpression
=
"Address"
UniqueName
=
"Address"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"City"
HeaderText
=
"City"
SortExpression
=
"City"
UniqueName
=
"City"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Phone"
HeaderText
=
"Phone"
SortExpression
=
"Phone"
UniqueName
=
"Phone"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Fax"
HeaderText
=
"Fax"
SortExpression
=
"Fax"
UniqueName
=
"Fax"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Email"
HeaderText
=
"Email"
SortExpression
=
"Email"
UniqueName
=
"Email"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CellPhone"
HeaderText
=
"CellPhone"
SortExpression
=
"CellPhone"
UniqueName
=
"CellPhone"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
HeaderStyle
Width
=
"100px"
/>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
SaveScrollPosition
=
"True"
>
</
Scrolling
>
</
ClientSettings
>
</
telerik:RadGrid
>
<
asp:Label
ID
=
"output"
runat
=
"server"
></
asp:Label
>
<
br
/>
<
asp:Button
ID
=
"export"
Text
=
"Export Data to Excel"
runat
=
"server"
/>
</
asp:Content
>
Imports
System.Data
Imports
System.Data.Sql
Imports
System.Data.SqlClient
Imports
Telerik.Web.UI
Partial
Class
internal_Clientlist
Inherits
System.Web.UI.Page
Dim
conn = System.Configuration.ConfigurationManager.ConnectionStrings(
"connection"
).ToString
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
If
Not
Page.IsPostBack
Then
MyFunctions.setCurrent(Page.Master.FindControl(
"clientLink"
))
bindGrid()
clientGrid.DataBind()
colDrop.DataSource = getColumns()
colDrop.DataValueField =
"colName"
colDrop.DataTextField =
"name"
colDrop.DataBind()
Session(
"searchDrop"
) =
""
'check the callback date
End
If
End
Sub
'page Load
'this sub gets the data for the grid
Protected
Friend
Sub
bindGrid()
Try
Dim
mytable
As
New
DataTable
mytable.Columns.Add(
"userid"
)
mytable.Columns.Add(
"firstname"
)
mytable.Columns.Add(
"Lastname"
)
mytable.Columns.Add(
"SchoolName"
)
mytable.Columns.Add(
"State"
)
mytable.Columns.Add(
"Interest"
)
mytable.Columns.Add(
"Rating"
)
mytable.Columns.Add(
"NextContactDate"
)
mytable.Columns.Add(
"InterestLevel"
)
mytable.Columns(
"userid"
).DataType = System.Type.
GetType
(
"System.Int16"
)
mytable.Columns(
"NextContactDate"
).DataType = System.Type.
GetType
(
"System.DateTime"
)
mytable.Columns(
"Rating"
).DataType = System.Type.
GetType
(
"System.Int16"
)
mytable.Columns(
"InterestLevel"
).DataType = System.Type.
GetType
(
"System.Int16"
)
Dim
username = Membership.GetUser.UserName
'if the search button is visible then we have to get the different sql
Dim
gridSql
If
(search.Visible)
Then
findSearchValue(gridSql)
Else
gridSql =
"SELECT tblUsers.UserId AS uid, FirstName, LastName, SchoolName, State, Interest, Rating, CONVERT(VARCHAR(10), NextContactDate, 101) AS NextContactDate, "
& _
"InterestLevel FROM tblUsers WHERE isDeleted='no' "
End
If
Using myconn
As
New
SqlConnection(conn)
myconn.Open()
Dim
reader
'if this is a salesman, we have to find the states they get.
If
(Roles.IsUserInRole(Membership.GetUser.UserName,
"salesman"
))
Then
reader =
New
SqlCommand(
"SELECT Name FROM userstates INNER JOIN states ON statefk = statesid WHERE username = '"
& username &
"'"
, myconn).ExecuteReader()
If
(reader.HasRows())
Then
gridSql &=
"AND( "
While
reader.Read()
gridSql &=
"State='"
& reader(
"Name"
) &
"' OR "
End
While
gridSql = gridSql.Substring(0, (gridSql.Length - 4)) &
") "
Else
gridSql =
"SELECT tblUsers.UserId AS uid, FirstName, LastName, Email FROM tblUsers WHERE isDeleted='no' AND State='blahblahblah' "
End
If
'if reader.hasrows
reader.Close()
End
If
'if isuserinrole
gridSql &=
"ORDER BY tblUsers.UserId"
reader =
New
SqlCommand(gridSql, myconn).ExecuteReader
While
reader.Read()
mytable.Rows.Add(reader(
"uid"
), reader(
"FirstName"
), reader(
"LastName"
), reader(
"SchoolName"
), reader(
"State"
), reader(
"Interest"
), _
reader(
"Rating"
), reader(
"NextContactDate"
), reader(
"InterestLevel"
))
End
While
myconn.Close()
End
Using
'using myconn
'Dim dataSource As New SqlDataSource
'dataSource.ConnectionString = conn
'dataSource.SelectCommand = gridSql
clientGrid.DataSource = mytable
Catch
ex
As
Exception
output.Text =
"<div class="
"outputDiv"
" style="
"color: red;"
">There was an error updating the customer. Please contact the systme administrator if the problem persists.</div>"
output.Show()
End
Try
End
Sub
'bindGrid
Protected
Sub
clientGrid_Init(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
clientGrid.Init
Dim
menu
As
GridFilterMenu = clientGrid.FilterMenu
Dim
i = 0
While
i < menu.Items.Count
If
(menu.Items(i).Text =
"NoFilter"
)
Then
menu.Items(i).Text =
"Clear"
ElseIf
menu.Items(i).Text =
"Contains"
Then
menu.Items(i).Text =
"Search"
Else
menu.Items(i).Visible =
False
End
If
i = i + 1
End
While
'while i <
End
Sub
'rad grid init
Protected
Sub
clientGrid_ItemCommand(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridCommandEventArgs)
Handles
clientGrid.ItemCommand
If
(e.CommandName =
"RowClick"
AndAlso
TypeOf
e.Item
Is
GridDataItem)
Then
Dim
id = e.Item.Cells(2).Text
Response.Redirect(
"EditClient.aspx?id="
& id)
End
If
End
Sub
'itemcommand
Protected
Sub
export_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
export.Click
Dim
mydate =
Date
.Now
Dim
fileName = mydate.Year &
"-"
& mydate.Month &
"-"
& mydate.Day &
" - Client List"
clientGrid.ExportSettings.OpenInNewWindow =
True
clientGrid.ExportSettings.ExportOnlyData =
True
clientGrid.ExportSettings.IgnorePaging =
True
'clientGrid.ExportSettings.FileName = fileName
clientGrid.MasterTableView.ExportToExcel()
End
Sub
'export click
'this function returns the data table for the column dropdown
Protected
Friend
Function
getColumns()
As
DataTable
Dim
myTable
As
New
DataTable
myTable.Columns.Add(
"colName"
)
myTable.Columns.Add(
"name"
)
myTable.Columns.Add(
"type"
)
myTable.Rows.Add(
"- Please Select -"
,
"- Please Select -"
,
"none"
)
myTable.Rows.Add(
"Address"
,
"Address"
,
"text"
)
myTable.Rows.Add(
"CallAt1Text"
,
"Call Attempt 1 Status"
,
"drop"
)
myTable.Rows.Add(
"CallAt2Text"
,
"Call Attempt 2 Status"
,
"drop"
)
myTable.Rows.Add(
"CallAt3Text"
,
"Call Attempt 3 Status"
,
"drop"
)
myTable.Rows.Add(
"CallAt4Text"
,
"Call Attempt 4 Status"
,
"drop"
)
myTable.Rows.Add(
"checkedLiterature"
,
"Checked Literature"
,
"check"
)
myTable.Rows.Add(
"City"
,
"City"
,
"text"
)
myTable.Rows.Add(
"ContactedDate"
,
"Contacted Date"
,
"date"
)
myTable.Rows.Add(
"DateLiteratureChecked"
,
"Date Literature Checked"
,
"date"
)
myTable.Rows.Add(
"DateRegistered"
,
"Date Registered"
,
"date"
)
myTable.Rows.Add(
"Email"
,
"Email Address"
,
"text"
)
myTable.Rows.Add(
"ZipCode"
,
"Zip"
,
"text"
)
myTable.Rows.Add(
"ExtendedZipCode"
,
"Extended Zip Code"
,
"text"
)
myTable.Rows.Add(
"Fax"
,
"Fax"
,
"text"
)
myTable.Rows.Add(
"Interest"
,
"Interest"
,
"drop"
)
myTable.Rows.Add(
"InterestLevel"
,
"Interest Level"
,
"drop"
)
myTable.Rows.Add(
"NextContactDate"
,
"Callback Date"
,
"date"
)
myTable.Rows.Add(
"NextContactTime"
,
"Callback Time"
,
"time"
)
myTable.Rows.Add(
"Notes"
,
"Notes"
,
"text"
)
myTable.Rows.Add(
"PhoneNumber"
,
"Phone Number"
,
"text"
)
myTable.Rows.Add(
"SalesNotes"
,
"Sales Notes"
,
"text"
)
myTable.Rows.Add(
"Title"
,
"Title"
,
"text"
)
myTable.Rows.Add(
"UserID"
,
"User Id"
,
"text"
)
myTable.Rows.Add(
"userPosition"
,
"Position"
,
"drop"
)
Return
myTable
End
Function
'getColums
Protected
Sub
clientGrid_NeedDataSource(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Handles
clientGrid.NeedDataSource
bindGrid()
End
Sub
'need data source
'find what they picked and then set the corresponding thing to visible
Protected
Sub
colDrop_SelectedIndexChanged(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
colDrop.SelectedIndexChanged
search.Visible =
True
'set all these to invisible initially
searchCheck.Visible =
False
searchDate.Visible =
False
searchDrop.Visible =
False
searchInput.Visible =
False
searchTime.Visible =
False
Dim
myTable = getColumns()
Dim
type
For
Each
i
In
myTable.Rows
If
(i(
"colName"
) = colDrop.SelectedValue)
Then
type = i(
"type"
)
Exit
For
End
If
Next
'for each
'now show the proper field
If
(type =
"text"
)
Then
searchInput.Visible =
True
ElseIf
(type =
"drop"
)
Then
searchDrop.Visible =
True
'only bind if this is a new dropdown item
If
(
Not
Session(
"searchDrop"
)
Is
Nothing
AndAlso
Session(
"searchDrop"
) <> colDrop.SelectedValue)
Then
Dim
searchTable
As
New
DataTable
searchTable.Columns.Add(
"value"
)
searchTable.Columns.Add(
"text"
)
'get all of the data from the database to create the dropdown
Using myconn
As
New
SqlConnection(conn)
myconn.Open()
Dim
reader =
New
SqlCommand(
"SELECT value FROM SearchDropItems WHERE colName ='"
& colDrop.SelectedValue &
"'"
, myconn).ExecuteReader()
While
reader.Read()
searchTable.Rows.Add(reader(0), reader(0))
End
While
myconn.Close()
End
Using
searchDrop.DataSource = searchTable
searchDrop.DataTextField =
"value"
searchDrop.DataValueField =
"value"
searchDrop.DataBind()
End
If
'if not
ElseIf
(type =
"time"
)
Then
searchTime.Visible =
True
ElseIf
(type =
"date"
)
Then
searchDate.Visible =
True
ElseIf
(type =
"check"
)
Then
searchCheck.Visible =
True
ElseIf
(type =
"none"
)
Then
search.Visible =
False
searchCheck.Visible =
False
searchDate.Visible =
False
searchDrop.Visible =
False
searchInput.Visible =
False
searchTime.Visible =
False
End
If
Session(
"searchDrop"
) = colDrop.SelectedValue
End
Sub
'colDrop index changed
'if they clicked search
Protected
Sub
search_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
search.Click
'bind the grid
bindGrid()
clientGrid.DataBind()
End
Sub
'search click
'this sub finds the proper search values
Protected
Friend
Sub
findSearchValue(
ByRef
sql
As
String
)
sql =
"SELECT tblUsers.UserId AS uid, FirstName, LastName, SchoolName, State, Interest, Rating, CONVERT(VARCHAR(10), NextContactDate, 101) AS NextContactDate, "
& _
"InterestLevel FROM tblUsers WHERE isDeleted='no' "
'see what type we are looking for
If
(searchInput.Visible)
Then
sql &=
"AND "
& colDrop.SelectedValue &
" like '%"
& searchInput.Text &
"%' "
ElseIf
(searchCheck.Visible)
Then
sql &=
"AND "
& colDrop.SelectedValue &
" = '"
& searchCheck.Checked &
"' "
ElseIf
(searchDate.Visible)
Then
sql &=
"AND "
& colDrop.SelectedValue &
" = '"
& searchDate.SelectedDate &
"' "
ElseIf
(searchDrop.Visible)
Then
sql &=
"AND "
& colDrop.SelectedValue &
" = '"
& searchDrop.SelectedValue &
"' "
ElseIf
(searchTime.Visible)
Then
sql &=
"AND "
& colDrop.SelectedValue &
" = '"
& searchTime.SelectedDate &
"' "
End
If
End
Sub
'findSearchValue
End
Class