By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

gridview paging weirdness +excel output

P: n/a

I dragged a table from a datasource on to my web form and the GridView
cpntrol was created. I turned on paging, and Edit and Delete buttons. I
ran the app and everything worked great - not a single line of code written
yet.

Then I wanted to add a simple feature where the user could filter out data
based on a value in a single column. I added a little code that set the
FilterExpression property of the SqlDataSource, and that seemed to work
fine
as well. Here is the FilterExpression code:

SqldataSource1.FilterExpression = "LastName = '" + txtFilterValue.Text +
"'";

This worked fine - I got a subset of the original data based on the last
name I entered into a text box.
The problem began if I tried to edit a record in the filtered data or go to
another page in the filtered data. Taking either of these actions resulted
in the restoration of the original unfiltered dataset. If I hit Edit on
the first record of the first page in the filtered dataset, I was switched
back to the first record in the unfiltered dataset and put in edit mode in
the GridView control. If I go to another page of data in the Filtered
dataset, the original dataset is resotred and I am sent to that page number
in the original dataset.

I tried taking the approach of changing the SelectCommand property of the
SqlDataSource object instead of using the FilterExpression property, but
that behaved the same way.

The only code I have is in the "Filter" button click event. I have no code
at all in the page_load event.

Also excel output problem:
This code:
Response.Clear()
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.No Cache)
Response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As System.IO.StringWriter = New
System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New
HtmlTextWriter(stringWrite)
SqlDataSource1.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()

Oututs the WHOLE PAGE to excel, not just the contents of the gridview
(buttons, labels, non gridview elements are inserted into the spreadsheet).
How can I just get the gridview data???
Feb 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ooops!

Posted Code was supposed to be 'gridview1.rendercontrol', not
sqldatasource1.rendercontrol (I tried that but nothing happened either)

Feb 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.