#1
  1. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    11

    add CommandArgument to button inside DataList


    How do I add a CommandArgument to a button inside a DataList? I need the CommandArgument to be the value inside the column ProjectID for the current ListItem. This is what I have so far, can't get passed it and don't know if I'm doing it right:
    Code:
     
    Sub dlstProjects_btnArgument(s As Object, e As DataListItemEventArgs)
    	If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    		' Retrieve the button control in the current DataListItem
    		Dim btnSelect As Button = CType(e.Item.FindControl("btnSelect"), Button)
    		' Set CommandArgument for current DataListItem
    		btnSelect.CommandArgument =
    	End If
    End Sub
    Thanks!
  2. #2
  3. Unholy Moderator
    ASP Mastermind (5000+ posts)

    Join Date
    Oct 2003
    Location
    In hell, where did you think?
    Posts
    12,026
    Rep Power
    659
    Maybe this will help.
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    11
    Thanks for the reply but I don't think that's what I'm looking for. The deals is, I have a datalist listing projects from a database. One of the items in the datalist is a button that I want to use if the user select a particular project. For me to get the project information I need the projectid, I can't really use the ItemIndex because the datalist could contain projects with projectid different from the itemindex. how do I create a command that will take the projectid and pass it into a SQL statement so I can get the project information. I hope it's clear.

    Thanks!
  6. #4
  7. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    11
    Still looking for solution. I tried this:
    Code:
    <asp:DataList id="dlstProjects" runat="server" OnItemCommand="DataList_ItemCommand">
    and
    Code:
     
    Sub DataList_ItemCommand(s As Object, e As DataListCommandEventArgs)
    	dlstProjects.SelectedIndex = e.Item.ItemIndex
    	Response.Redirect("http://www.cnn.com")
    End Sub
    That way I can get the ProjectID from the DataSet based on the ItemIndex, but for some reason my buttons don't call the subroutine. My buttons are inside the <ItemTemplate>

    Thanks!
  8. #5
  9. Unholy Moderator
    ASP Mastermind (5000+ posts)

    Join Date
    Oct 2003
    Location
    In hell, where did you think?
    Posts
    12,026
    Rep Power
    659
    An easier way to do this would be to use a Hyperlink Column, then call another page and pass it the projectID.

    For an example of how to do this, download and review my .NET Tutorial at the top of this forum.
  10. #6
  11. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    11
    accomplished:
    Code:
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then 
    	dlstProjects.SelectedIndex = e.Item.ItemIndex 
    	Session("ProjectID") = CType(dlstProjects.SelectedItem.FindControl("lblProjectID"), Label).Text 
    	Response.Redirect("viewproject.aspx")
    End If
    I added a label with id="lblProjectID" databound with the Db column ProjectID and made it Visible="False"

    Thanks!

Similar Threads

  1. button inside DataList error: Name 'btnNext' is not declared
    By maxtrixx in forum .NET Development
    Replies: 0
    Last Post: January 5th, 2005, 03:22 PM
  2. handling radio button event in user controls datalist
    By manu_srinivasa in forum .NET Development
    Replies: 1
    Last Post: November 26th, 2004, 07:43 AM
  3. Accessing a DropDownList inside a datalist
    By BillyWebb in forum .NET Development
    Replies: 1
    Last Post: November 9th, 2004, 10:03 AM
  4. Conditional Statements inside datalist or datagrid
    By rletanab in forum .NET Development
    Replies: 3
    Last Post: September 21st, 2004, 03:59 AM
  5. Replies: 1
    Last Post: October 2nd, 2003, 09:34 AM

IMN logo majestic logo threadwatch logo seochat tools logo