Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > 'Gridview1' fired event Sorting which wasn't handled

Reply
Thread Tools

'Gridview1' fired event Sorting which wasn't handled

 
 
Vincent
Guest
Posts: n/a
 
      02-23-2008
Hi,

I created a gridview bound to the roles tables with this code:
rolesArray = Roles.GetAllRoles()
Gridview1.DataSource = rolesArray
Gridview1.DataBind()

The gridview has following classic properties:
<asp:GridView runat="server" id="Gridview1" AllowPaging="True"
AllowSorting="true"
pagesize="3" />

When clicking on the bar containing the pagenumber of the gridview in order
to go the next page, i get:
"The GridView 'Gridview1' fired event PageIndexChanging which wasn't
handled."

When i click on the field for sorting, i get the error:
"The GridView 'Gridview1' fired event Sorting which wasn't handled"

Thanks for help
Vincent


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      02-23-2008
"Vincent" <vi,@sd.cv> wrote in message
news:%(E-Mail Removed)...

> When clicking on the bar containing the pagenumber of the gridview in
> order to go the next page, i get:
> "The GridView 'Gridview1' fired event PageIndexChanging which wasn't
> handled."
>
> When i click on the field for sorting, i get the error:
> "The GridView 'Gridview1' fired event Sorting which wasn't handled"


That's because you haven't wired up the paging and sorting events...

<asp:GridView runat="server" id="Gridview1"
AllowPaging="True" AllowSorting="true" pagesize="3"
OnPageIndexChanging="Gridview1_PageIndexChanging"
OnSorting="Gridview1_Sorting"
/>

protected void Gridview1_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
// do something
}

protected void Gridview1_Sorting(object sender, GridViewSortEventArgs e)
{
// do something
}


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
Vincent
Guest
Posts: n/a
 
      02-24-2008
Thanks for your reply.

Normally, when creating a gridview bound to a sqldatasource, the sorting /
paging occur automatically. This is new to me so what code do you mean with
// do something
Does it exist something like 'sort' or 'paging' ...?


Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> "Vincent" <vi,@sd.cv> wrote in message
> news:%(E-Mail Removed)...
>
>> When clicking on the bar containing the pagenumber of the gridview in
>> order to go the next page, i get:
>> "The GridView 'Gridview1' fired event PageIndexChanging which wasn't
>> handled."
>>
>> When i click on the field for sorting, i get the error:
>> "The GridView 'Gridview1' fired event Sorting which wasn't handled"

>
> That's because you haven't wired up the paging and sorting events...
>
> <asp:GridView runat="server" id="Gridview1"
> AllowPaging="True" AllowSorting="true" pagesize="3"
> OnPageIndexChanging="Gridview1_PageIndexChanging"
> OnSorting="Gridview1_Sorting"
> />
>
> protected void Gridview1_PageIndexChanging(object sender,
> GridViewPageEventArgs e)
> {
> // do something
> }
>
> protected void Gridview1_Sorting(object sender, GridViewSortEventArgs e)
> {
> // do something
> }
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      02-24-2008
"Vincent" <vi,@sd.cv> wrote in message
news:(E-Mail Removed)...

> Normally, when creating a gridview bound to a sqldatasource, the sorting /
> paging occur automatically.


Yes, but you're not using the SqlDataSource directly i.e. you're not setting
the GridView's DataSourceID property - instead, you're using a custom object
as the GridView's datasource e.g.
rolesArray = Roles.GetAllRoles()
Gridview1.DataSource = rolesArray
Gridview1.DataBind()

That's why you need to add event handlers for the sorting and paging
functionality manually:
http://forums.asp.net/p/956540/1177923.aspx


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Vincent
Guest
Posts: n/a
 
      02-24-2008
Thanks, i'll read it

"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "Vincent" <vi,@sd.cv> wrote in message
> news:(E-Mail Removed)...
>
>> Normally, when creating a gridview bound to a sqldatasource, the sorting
>> / paging occur automatically.

>
> Yes, but you're not using the SqlDataSource directly i.e. you're not
> setting the GridView's DataSourceID property - instead, you're using a
> custom object as the GridView's datasource e.g.
> rolesArray = Roles.GetAllRoles()
> Gridview1.DataSource = rolesArray
> Gridview1.DataBind()
>
> That's why you need to add event handlers for the sorting and paging
> functionality manually:
> http://forums.asp.net/p/956540/1177923.aspx
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Vincent
Guest
Posts: n/a
 
      02-24-2008
Hi Mark,

i used the code you gave me but there is an error when sorting only:
"Unable to cast object of type 'System.String[]' to type
'System.Data.DataTable' "
at line: Dim dt As DataTable = Gridview1.DataSource

i tried several things (using string() instead of Datatable ...) but could
not find the solution.

the whole code:
Protected Sub Gridview1_Sorting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewSortEventArgs) Handles Gridview1.Sorting
Dim dt As DataTable = Gridview1.DataSource
If Not IsDBNull(dt) Then
Dim dv As DataView = New DataView(dt)
dv.Sort = e.SortExpression
Gridview1.DataSource = dv
Gridview1.DataBind()
End If
End Sub




"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "Vincent" <vi,@sd.cv> wrote in message
> news:(E-Mail Removed)...
>
>> Normally, when creating a gridview bound to a sqldatasource, the sorting
>> / paging occur automatically.

>
> Yes, but you're not using the SqlDataSource directly i.e. you're not
> setting the GridView's DataSourceID property - instead, you're using a
> custom object as the GridView's datasource e.g.
> rolesArray = Roles.GetAllRoles()
> Gridview1.DataSource = rolesArray
> Gridview1.DataBind()
>
> That's why you need to add event handlers for the sorting and paging
> functionality manually:
> http://forums.asp.net/p/956540/1177923.aspx
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      02-24-2008
"Vincent" <vi,@sd.cv> wrote in message
news:(E-Mail Removed)...

> "Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>> "Vincent" <vi,@sd.cv> wrote in message
>> news:(E-Mail Removed)...
>>
>>> Normally, when creating a gridview bound to a sqldatasource, the sorting
>>> / paging occur automatically.

>>
>> Yes, but you're not using the SqlDataSource directly i.e. you're not
>> setting the GridView's DataSourceID property - instead, you're using a
>> custom object as the GridView's datasource e.g.
>> rolesArray = Roles.GetAllRoles()
>> Gridview1.DataSource = rolesArray
>> Gridview1.DataBind()
>>
>> That's why you need to add event handlers for the sorting and paging
>> functionality manually:
>> http://forums.asp.net/p/956540/1177923.aspx

>
> i used the code you gave me but there is an error when sorting only:
> "Unable to cast object of type 'System.String[]' to type
> 'System.Data.DataTable' "
> at line: Dim dt As DataTable = Gridview1.DataSource


Well, there would be... A DataTable is a DataTable datatype (obviously!),
but a GridView's DataSource is an object datatype so that various datatypes
can be used as datasources for databound controls - you can't dimension a
DataTable as an object directly... I can only imagine that you're not using
Option Strict, otherwise I'm pretty sure your code wouldn't have compiled -
it certainly wouldn't have compiled in C#...

> i tried several things (using string() instead of Datatable ...) but could
> not find the solution.


Try this:
Dim dt As DataTable = DirectCast(Gridview1.DataSource, DataTable)


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Vincent
Guest
Posts: n/a
 
      02-24-2008
Thanks again, but i still get the same error at line:
Dim dt As DataTable = DirectCast(Gridview1.DataSource, DataTable)



"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "Vincent" <vi,@sd.cv> wrote in message
> news:(E-Mail Removed)...
>
>> "Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
>> news:(E-Mail Removed)...
>>> "Vincent" <vi,@sd.cv> wrote in message
>>> news:(E-Mail Removed)...
>>>
>>>> Normally, when creating a gridview bound to a sqldatasource, the
>>>> sorting / paging occur automatically.
>>>
>>> Yes, but you're not using the SqlDataSource directly i.e. you're not
>>> setting the GridView's DataSourceID property - instead, you're using a
>>> custom object as the GridView's datasource e.g.
>>> rolesArray = Roles.GetAllRoles()
>>> Gridview1.DataSource = rolesArray
>>> Gridview1.DataBind()
>>>
>>> That's why you need to add event handlers for the sorting and paging
>>> functionality manually:
>>> http://forums.asp.net/p/956540/1177923.aspx

>>
>> i used the code you gave me but there is an error when sorting only:
>> "Unable to cast object of type 'System.String[]' to type
>> 'System.Data.DataTable' "
>> at line: Dim dt As DataTable = Gridview1.DataSource

>
> Well, there would be... A DataTable is a DataTable datatype (obviously!),
> but a GridView's DataSource is an object datatype so that various
> datatypes can be used as datasources for databound controls - you can't
> dimension a DataTable as an object directly... I can only imagine that
> you're not using Option Strict, otherwise I'm pretty sure your code
> wouldn't have compiled - it certainly wouldn't have compiled in C#...
>
>> i tried several things (using string() instead of Datatable ...) but
>> could not find the solution.

>
> Try this:
> Dim dt As DataTable = DirectCast(Gridview1.DataSource, DataTable)
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      02-24-2008
"Vincent" <vi,@sd.cv> wrote in message
news:%23%(E-Mail Removed)...

[top-posting corrected]

>>> i used the code you gave me but there is an error when sorting only:
>>> "Unable to cast object of type 'System.String[]' to type
>>> 'System.Data.DataTable' "
>>> at line: Dim dt As DataTable = Gridview1.DataSource

>>
>> Well, there would be... A DataTable is a DataTable datatype (obviously!),
>> but a GridView's DataSource is an object datatype so that various
>> datatypes can be used as datasources for databound controls - you can't
>> dimension a DataTable as an object directly... I can only imagine that
>> you're not using Option Strict, otherwise I'm pretty sure your code
>> wouldn't have compiled - it certainly wouldn't have compiled in C#...
>>
>>> i tried several things (using string() instead of Datatable ...) but
>>> could not find the solution.

>>
>> Try this:
>> Dim dt As DataTable = DirectCast(Gridview1.DataSource, DataTable)

>
> Thanks again, but i still get the same error at line:
> Dim dt As DataTable = DirectCast(Gridview1.DataSource, DataTable)


Hmm - OK... What datatype is GridView1.DataSource? Can it even be cast to a
DataTable type...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Vincent
Guest
Posts: n/a
 
      02-25-2008
The datasource are the roles from the table 'aspnet_roles' created when
creating membership users:
so the datasource is of type array string.

dim rolesArray() As String
rolesArray = Roles.GetAllRoles()
Gridview1.DataSource = rolesArray
Gridview1.DataBind()

Thanks


"Mark Rae [MVP]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> "Vincent" <vi,@sd.cv> wrote in message
> news:%23%(E-Mail Removed)...
>
> [top-posting corrected]
>
>>>> i used the code you gave me but there is an error when sorting only:
>>>> "Unable to cast object of type 'System.String[]' to type
>>>> 'System.Data.DataTable' "
>>>> at line: Dim dt As DataTable = Gridview1.DataSource
>>>
>>> Well, there would be... A DataTable is a DataTable datatype
>>> (obviously!), but a GridView's DataSource is an object datatype so that
>>> various datatypes can be used as datasources for databound controls -
>>> you can't dimension a DataTable as an object directly... I can only
>>> imagine that you're not using Option Strict, otherwise I'm pretty sure
>>> your code wouldn't have compiled - it certainly wouldn't have compiled
>>> in C#...
>>>
>>>> i tried several things (using string() instead of Datatable ...) but
>>>> could not find the solution.
>>>
>>> Try this:
>>> Dim dt As DataTable = DirectCast(Gridview1.DataSource, DataTable)

>>
>> Thanks again, but i still get the same error at line:
>> Dim dt As DataTable = DirectCast(Gridview1.DataSource, DataTable)

>
> Hmm - OK... What datatype is GridView1.DataSource? Can it even be cast to
> a DataTable type...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired? Num GG Javascript 2 11-17-2008 08:56 PM
The GridView 'GridView1' fired event Sorting which wasn't handled. rajendrasedhain Software 0 07-08-2008 07:52 PM
Error :The DetailsView 'dv' fired event ModeChanging which wasn't handled. rote ASP .Net 0 01-29-2008 11:29 PM
The GridView 'GridView1' fired event Sorting which wasn't handled Arjen ASP .Net 3 11-01-2007 11:13 PM
fired event Sorting which wasn't handled - sorting and SelectedIndexChanged Jason ASP .Net Web Controls 0 10-04-2006 02:19 PM



Advertisments