Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: add CommandArgument to button inside DataList

Results 1 to 6 of 6
Share This Thread →
  1. #1
    maxtrixx is offline Contributing User
    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    10

    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
    Memnoch's Avatar
    Memnoch is offline Unholy Moderator
    Join Date
    Oct 2003
    Location
    In hell, where did you think?
    Posts
    12,026
    Rep Power
    658
    Maybe this will help.

  3. #3
    maxtrixx is offline Contributing User
    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    10
    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!

  4. #4
    maxtrixx is offline Contributing User
    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    10
    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!

  5. #5
    Memnoch's Avatar
    Memnoch is offline Unholy Moderator
    Join Date
    Oct 2003
    Location
    In hell, where did you think?
    Posts
    12,026
    Rep Power
    658
    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.

  6. #6
    maxtrixx is offline Contributing User
    Join Date
    Jul 2004
    Location
    ASP Free Forums
    Posts
    372
    Rep Power
    10
    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!

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

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, 02: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, 06:43 AM
  3. Accessing a DropDownList inside a datalist
    By BillyWebb in forum .NET Development
    Replies: 1
    Last Post: November 9th, 2004, 09:03 AM
  4. Conditional Statements inside datalist or datagrid
    By rletanab in forum .NET Development
    Replies: 3
    Last Post: September 21st, 2004, 02:59 AM
  5. Replies: 1
    Last Post: October 2nd, 2003, 08:34 AM

ASP Free Advertisers and Affiliates