 |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
 | This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

December 3rd, 2009, 01:34 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Paging
Hello Sir, Once again I am in trouble. Now the paging with gridview is getting me problem. I have enabled paging and set its page size to 5.
Whenever there are more than 2 pages then it does not work and running application in debugging mode it reports as "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
One strange thing is when I move from page no.1 to 2 and vice versa then it works fine but as soon as I move to page 3 or more then back to some other page does not work i.e moving from page 1 or 2 to 3 works at one time but on successive moves paging does not work.
page index is set to 0 by default.
I don't know how to fix it. Please give me some suggestion as I have been using paging with gridview at many places but why here it is getting me problem I don't know.
My Markup code is
Code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames ="Id"
DataSourceID="SqlDataSource1" PageSize="5">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="play1" HeaderText="Play" Text="Play" />
<asp:BoundField DataField="SongName" HeaderText="Song Name" SortExpression="SongName" />
<asp:ButtonField ButtonType="Button" CommandName="download1" HeaderText="Download" Text="Download" />
</Columns>
</asp:GridView>
I have enabled the rowcomand event and the code behind file is
Code:
Protected Sub GridView1_RowCommand1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
con.Open()
Dim play_db As Integer = Convert.ToInt32(GridView1.DataKeys(e.CommandArgument).Values("Id").ToString())
other code.......
con.Close()
End Sub
whenever I jump from one page to another then it shows the above mentioned error report.
Sir please guide me regarding this. Any help is highly respected.
Thank you....
Last edited by sophia; December 3rd, 2009 at 01:45 PM..
|
|

December 4th, 2009, 03:54 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
The RowCommand also fires for sorting. You need to look at the CommandName and only execute your code when you really want to.
http://msdn.microsoft.com/en-us/libr...mmandname.aspx
Imar
|
|

December 4th, 2009, 10:51 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Hello sir, thank you for link.
I have one page called Music.aspx Here I have given two functionalities "play" & "Download". playing is working fine but downloading option throws an error.
Mark up is something like this one
Code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames ="Id"
DataSourceID="SqlDataSource1" PageSize="5">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="play1" HeaderText="Play" Text="Play" />
<asp:BoundField DataField="SongName" HeaderText="Song Name" SortExpression="SongName" />
<asp:ButtonField ButtonType="Button" CommandName="download1" HeaderText="Download" Text="Download" />
</Columns>
And the code behind file is like;
Code:
Protected Sub GridView1_RowCommand1(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
con.Open()
'Me.pageindex()
'Dim play_index As Integer = Convert.ToInt32(e.CommandArgument)
'Dim row As GridViewRow = GridView1.Rows(0)
Dim play_index_db As Integer = GridView1.DataKeys(e.CommandArgument).Values("Id").ToString() 'Convert.ToInt32(row.Cells(1).Text)
Dim s As String = "select SongPath from Music where Id = " & play_index_db
Dim cmd As New SqlCommand(s, con)
Dim p As String = Convert.ToString(cmd.ExecuteScalar())
Dim s1 As String = "select SongExtn from Music where Id = " & play_index_db
Dim cmd1 As New SqlCommand(s1, con)
Dim p1 As String = Convert.ToString(cmd1.ExecuteScalar())
Dim s2 As String = "select SongName from Music where Id = " & play_index_db
Dim cmd2 As New SqlCommand(s2, con)
Dim p2 As String = Convert.ToString(cmd2.ExecuteScalar())
If e.CommandName = "play1" Then
playing logic goes here..............
End If
If e.CommandName = "download1" Then
Response.ContentType = "Music/.mp3"
Response.AppendHeader("Content-Disposition", ("attachment; filename=" & p2 & p1))
Response.TransmitFile(p)
Response.[End]()
End If
con.Close()
End Sub
when ever I click download button then error generated is like
Code:
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'ID3 '.
First day when I created this page then it was working fine but after some days it is generating problem like this.
Why this error is here and how I can resolve this.
Hope I will be resolving this with your response.
Thank you......
|
|

December 4th, 2009, 11:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am a bit confused by this. Is this related to the original message? If not, can you please post a *new* message for a new topic? Otherwise, things get just too confusing...
Cheers,
Imar
|
|

December 4th, 2009, 11:34 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
New topic- Downloading
Sir this is not related to first post.
I have one page called Music.aspx Here I have given two functionalities "play" & "Download". playing is working fine but downloading option throws an error.
Mark up is something like this one
Code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames ="Id"
DataSourceID="SqlDataSource1" PageSize="5">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="play1" HeaderText="Play" Text="Play" />
<asp:BoundField DataField="SongName" HeaderText="Song Name" SortExpression="SongName" />
<asp:ButtonField ButtonType="Button" CommandName="download1" HeaderText="Download" Text="Download" />
</Columns>
And the code behind file is like;
Code:
Protected Sub GridView1_RowCommand1(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
con.Open()
'Me.pageindex()
'Dim play_index As Integer = Convert.ToInt32(e.CommandArgument)
'Dim row As GridViewRow = GridView1.Rows(0)
Dim play_index_db As Integer = GridView1.DataKeys(e.CommandArgument).Values("Id").ToString() 'Convert.ToInt32(row.Cells(1).Text)
Dim s As String = "select SongPath from Music where Id = " & play_index_db
Dim cmd As New SqlCommand(s, con)
Dim p As String = Convert.ToString(cmd.ExecuteScalar())
Dim s1 As String = "select SongExtn from Music where Id = " & play_index_db
Dim cmd1 As New SqlCommand(s1, con)
Dim p1 As String = Convert.ToString(cmd1.ExecuteScalar())
Dim s2 As String = "select SongName from Music where Id = " & play_index_db
Dim cmd2 As New SqlCommand(s2, con)
Dim p2 As String = Convert.ToString(cmd2.ExecuteScalar())
If e.CommandName = "play1" Then
playing logic goes here..............
End If
If e.CommandName = "download1" Then
Response.ContentType = "Music/.mp3"
Response.AppendHeader("Content-Disposition", ("attachment; filename=" & p2 & p1))
Response.TransmitFile(p)
Response.[End]()
End If
con.Close()
End Sub
when ever I click download button then error generated is like
Code:
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'ID3 '.
First day when I created this page then it was working fine but after some days it is generating problem like this.
Why this error is here and how I can resolve this.
Hope I will be resolving this with your response.
Thank you......
|
|

December 4th, 2009, 02:05 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If it's not related to this post, why do you repeat the exact same question here again? I am not deaf; I just asked you to create separate threads for separate topics.....
If you create a new thread, please post it in a relevant ASP.NET forum from this list: http://p2p.wrox.com/asp-net-2-0-437/ or this list: http://p2p.wrox.com/asp-net-3-5-436/ as the topic doesn't seem to be related to the book ASP.NET 2 Instant Results.
Cheers,
Imar
|
|

December 4th, 2009, 02:08 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Sir, till I waited for your reply, I created a new fresh page. Then it worked out as previous. Then the difference that I could find was Update panel.
I don't know how this update panel was getting me problem while downloading a file but still the playing was working. the error was
Code:
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'ID3 '.
Although the problem is solved by removing the update panel but still want to know why update panel was getting problem while downloading and not at the time of playing, and generated the above mentioned error.
Thank you.......
|
|

December 4th, 2009, 02:11 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You're not really getting my message about separate threads are you?
Anyway, I think it's caused by the call to Response.TransmitFile(p). UpdatePanels cause a partial postback with a partial response, while TransmitFile returns a full response for a request. The two aren't compatible AFAIK.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

December 4th, 2009, 02:11 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
sorry for inconvenience you had.
I'll take care of it next time.
Sorry once again.
Keep smiling
|
|

December 4th, 2009, 02:15 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It's not about the inconvenience I am having. It's about best practices in "thread management" so you, me and others in the future may find this thread and find useful, relevant information and not having to wade through pages and pages of off-topic stuff until they find what they came for originally....
Imar
|
|
 |