|
-
Dec 10th, 2002, 07:09 PM
#1
Thread Starter
New Member
ASP.Net Problem with Linkbutton commandargument
I am trying to send command arguments when a linkbutton is clicked. I am having no problem sending a string as follows:
commandargument="Some String"
and I have no problems sending a bound value scuh as:
commandargument=<%# DataBinder.Eval(Container.DataItem, "SOME_VALUE")%>
Where I have a problem is in my desire to combine the two. I want to concatenate a string with the bound value. I continually get tag not properly formed errors or the binding string itself is returned. I have tried single quotes, double quotes, combinations of the two as follows:
commandargument="Some String" + <%# DataBinder.Eval(Container.DataItem, "SOME_VALUE")%>
commandargument="Some String"<%# DataBinder.Eval(Container.DataItem, 'SOME_VALUE')%>
commandargument='Some String<%# DataBinder.Eval(Container.DataItem, "SOME_VALUE")%>'
commandargument="Some String<%# DataBinder.Eval(Container.DataItem, "SOME_VALUE")%>"
CAN THIS BE DONE??
-
Dec 11th, 2002, 01:32 AM
#2
It can be done, but it has to be done in the <script runat=server> tags or in the code behind.
You cannot do it in the aspx file directly.
Do the AddEventHandler method.
Optionally, you can (if this a datagrid or datalist) set a datakeys on the datagrid or datalist. Then, use onEditCommand and then in the datagrid tag, onEditCommand="someCommand"
In the someCommand, use sender.datakeys(e.item.itemindex) to retreive your key value from the data grid. Once done, jump to the appropriate method that handles the event.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Dec 11th, 2002, 07:12 AM
#3
Thread Starter
New Member
RESOLVED Commandargument Issue
I found a solution to my problem. I merely had to add the string I wanted to concatenate inside the script tags as follows:
commandargument=<%# "STRING WITH DELIMITERS" & DataBinder.Eval(Container.DataItem, "SOME_VALUE" )%>
This allows me to pass a string with delimters, the last items of which is the value of the binding. I can then parse the string.
-
Dec 11th, 2002, 12:08 PM
#4
Note taken. Thanks for the follow up
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
May 20th, 2003, 03:20 PM
#5
PowerPoster
Question?
Looks like you guys know what you are doing so here goes-
Why am I not getting data in the DataKeys collection?
Code:
Private Sub DataList1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
Dim lblLabel As Label
Dim intID
Dim strLabelID As String
'---retrieves the key for the row---
intID = DataList1.DataKeys(e.Item.ItemIndex)
'---find the label control containing the id
lblLabel = CType(e.Item.FindControl("lblID"), Label)
strLabelID = lblLabel.Text
Dim v As New IntranetVariables()
Response.Redirect _
(v.url_EmployeeAnnouncements_Detail & "?ex=" & strLabelID, True)
End Sub
-
May 20th, 2003, 03:32 PM
#6
PowerPoster
Did you remeber to set the DataKeys property on the grid?
-
May 21st, 2003, 07:15 AM
#7
PowerPoster
you are right! That's what was missing. But the strange thing I don't understand is why this example doesn't have to set it on the page and it works! I used this example to do my work.
http://www.ondotnet.com/pub/a/dotnet.../datalist.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|