Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CausesValidation on Edit/Update in Datagrid

Status
Not open for further replies.

mtl77

Programmer
May 27, 2003
31
0
0
CA
Does anyone know how to set causes validation to false when a datagrid edit/update/cancel linkbutton is fired? I have heard that it is done in the ItemCommand event but i am struggling to figure that out. Any suggestions?

Thanks in advance for any responses,

KF.
 
It's easy. Just set it on your aspx page, something like this:

<asp:linkbutton CommandName="Update" Text="Update" Runat="server" ID="lbtnItemUpdate" CausesValidation="true" />

<asp:linkbutton CommandName="Cancel" Text="Cancel" Runat="server" ID="lbtnItemCancel" CausesValidation="False" />
 
on code-behind page: 2 steps:

1)
Private Sub myDatalist_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles myDatalist.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then
CType(e.Item.FindControl("lbtnItemUpdate"), LinkButton).CommandArgument = e.Item.ItemIndex
end if
end sub


2)

Private Sub myDatalist_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles myDatalist.ItemCommand

If e.CommandName = "Update" Then
If e.Item.ItemIndex = e.CommandArgument And e.Item.ItemType = ListItemType.EditItem Then

Ctype(e.Item.FindControl("lbtnItemUpdate"), linkbutton).causesValidation = false

end if

end if
end sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top