L
Leon Mayne
Hello,
I have a gridview that's bound to a generic list of business objects and am
using the RowCommand event to capture user clicks on actions. This was
working fine up until today, but now e.CommandArgument being passed into the
RowCommand event handler is always coming back as an empty string and
causing an invalid cast exception.
The GridView itself has a hyperlink field to display the object name, and
several TemplateFields to allow the user to perform actions on the record
(such as move up, move down, delete etc.). Here's one of the template
fields:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="imgDelete1" runat="server" CausesValidation="false"
CommandName="deletesection" CommandArgument='<%#Eval("PolicySectionId")%>'
ImageUrl="~/Images/delete.gif" AlternateText="Delete" OnClientClick="return
confirm('Are you sure you want to delete the selected section?');" />
</ItemTemplate>
</asp:TemplateField>
You can see that I am manually setting the CommandArgument to the
PolicySectionId property of the business object when it binds. Then in my
code behind file I have:
Private Sub GridView_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand
' Check what action we are performing
Select Case e.CommandName
Case "deletesection"
' Delete (archive) the section
Dim objSection As New SafetyPolicySection(CInt(e.CommandArgument))
objSection.Archive(CType(Session("CurrentUser"), User).UserId)
' etc
End Select
Me.BindGridView()
End Sub
This used to work OK, but now e.CommandArgument is an empty string each time
I try. I checked the history of the files and there doesn't seem to be any
changes that would affect the functionality. Does anyone know what might be
wrong?
I have a gridview that's bound to a generic list of business objects and am
using the RowCommand event to capture user clicks on actions. This was
working fine up until today, but now e.CommandArgument being passed into the
RowCommand event handler is always coming back as an empty string and
causing an invalid cast exception.
The GridView itself has a hyperlink field to display the object name, and
several TemplateFields to allow the user to perform actions on the record
(such as move up, move down, delete etc.). Here's one of the template
fields:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="imgDelete1" runat="server" CausesValidation="false"
CommandName="deletesection" CommandArgument='<%#Eval("PolicySectionId")%>'
ImageUrl="~/Images/delete.gif" AlternateText="Delete" OnClientClick="return
confirm('Are you sure you want to delete the selected section?');" />
</ItemTemplate>
</asp:TemplateField>
You can see that I am manually setting the CommandArgument to the
PolicySectionId property of the business object when it binds. Then in my
code behind file I have:
Private Sub GridView_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand
' Check what action we are performing
Select Case e.CommandName
Case "deletesection"
' Delete (archive) the section
Dim objSection As New SafetyPolicySection(CInt(e.CommandArgument))
objSection.Archive(CType(Session("CurrentUser"), User).UserId)
' etc
End Select
Me.BindGridView()
End Sub
This used to work OK, but now e.CommandArgument is an empty string each time
I try. I checked the history of the files and there doesn't seem to be any
changes that would affect the functionality. Does anyone know what might be
wrong?