Sunday, March 25, 2012

Deleting from SQL table using two arguments

I am trying to delete from a SQL table using two arguments, I currently use the following on the aspx page:

<ItemTemplate>
<asp:LinkButton ID="cmdDeleteJob" runat="server" CommandName="CancelJob" Text="Delete" CssClass="CommandButton" CommandArgument='<%# Bind("Type_of_service") %>' OnClientClick="return confirm('Are you sure you want to delete this item?');"></asp:LinkButton>
</ItemTemplate>

and then I use the following on the aspx.vb page:

If e.CommandName = "CancelJob" Then

Dim typeService As Integer = CType(e.CommandArgument, Integer)
Dim typeDesc As String = ""

Dim wsDelete As New page1
wsDelete.deleteAgencySvcs(typeService)

gvTech.DataBind()

I need to be able to pick up two CommandArguments.

Is this Template in a GridView? if so, is the second argument the same for all rows? if yes, then store that arugment in the DataKeyNames property of the grid. If not, then you can try using a pipe or literal separator for your command argument and then parse it out in the handler by using split().

Hope that helps,

--D

|||

Hi dannyo1984,

Pass Two Areguments like this

<ItemTemplate>

<asp:LinkButtonID="lnkCreator"runat="server"

Text='<%# Eval ("fullname") %>'

CommandName="Select"

CommandArgument='<%# DataBinder.Eval(Container, "DataItem.lock", "{0}")+" "+ DataBinder.Eval(Container, "DataItem.ChangeRequest_No", "{0}")%>'OnCommand="lnkCreator_Command">

</asp:LinkButton>

</ItemTemplate>

in ASX.VB Page

ProtectedSub lnkCreator_Command(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.CommandEventArgs)

Dim strStringAsString = e.CommandArgument.ToString()

Dim resultArrayAsString() = strString.Split(" ")

EndSub

Regards,

Naveen

|||

How do I separate the two column values in the VB? I need both to be string values.

|||

On the ASPX page I used.

<asp:LinkButton ID="cmdDeleteJob" runat="server" CommandName="CancelJob" Text="Delete" CssClass="CommandButton" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Type_of_Service") +"|"+ DataBinder.Eval(Container.DataItem, "Other_Service") %>' OnClientClick="return confirm('Are you sure you want to delete this item?');"></asp:LinkButton>

On the VB side I used this, to get the values.

Dim delimStr As String = "|"

Dim delimiter As Char() = delimStr.ToCharArray()

Dim arguments As String() = Convert.ToString(e.CommandArgument).Split(delimiter)

Dim typeservice As Integer = Convert.ToInt32(arguments(0))

Dim Value2 As String = Convert.ToString(arguments(1))

Dim otherService As String = Value2

No comments:

Post a Comment