Results 1 to 7 of 7

Thread: ASP.Net Problem with Linkbutton commandargument

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    2

    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??

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    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)

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    2

    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.

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    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)

  5. #5
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    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

  6. #6
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Did you remeber to set the DataKeys property on the grid?

  7. #7
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    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
  •  



Click Here to Expand Forum to Full Width