Results 1 to 5 of 5

Thread: *Resolved* Datalist and asp:Button control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    90

    *Resolved* Datalist and asp:Button control

    I have a Datalist with its OnItemCommand set to a sub that process the request (subProcessRequest). I have an asp:Button in the ItemTemplate.

    My asp:Button has its CommandArgument set to a value from the datasource. It also has its CommandName set to "Add".

    My problem is the event "subProcessRequest" never fires when the button is clicked.

    HOWEVER, if I change it to an asp:Linkbutton it works fine. Why?
    Last edited by jstansell; Feb 27th, 2004 at 01:59 PM.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Here's some code that works, not sure what might be happening with your code though:
    PHP Code:
    <%@ Import Namespace="System.Data" %>
    <
    script language="C#" runat="server">
    protected 
    override void OnLoad(EventArgs e)
    {
        if (!
    Page.IsPostBack)
        {
            
    bindList();
        }
    }
    private 
    void bindList()
    {
        
    dlTest.DataSource getData();
        
    dlTest.DataBind();
    }
    private 
    DataTable getData()
    {
        
    DataTable dt = new DataTable();
        
    dt.Columns.Add(new DataColumn("id"));
        
    addRow(dt"1");
        
    addRow(dt"2");
        return 
    dt;
    }
    private 
    void addRow(DataTable dtstring id)
    {
        
    DataRow row dt.NewRow();
        
    row["id"] = id;
        
    dt.Rows.Add(row);
    }
    protected 
    void dlTest_ItemCommand(object senderDataListCommandEventArgs e)
    {
        
    Response.Write("Editing: " e.CommandArgument.ToString());
    }
    </
    script>
    <
    html>
        <
    head>
            <
    title></title>
        </
    head>
        <
    body>
            <
    form runat="server" ID="Form1">
                <
    asp:DataList ID="dlTest" Runat="server" OnItemCommand="dlTest_ItemCommand">
                    <
    ItemTemplate>
                        <
    asp:Button CommandArgument='<%# DataBinder.Eval ( Container.DataItem , "id" ) %>' 
                            
    CommandName="test" Runat="server" Text="Click Me"/>
                    </
    ItemTemplate>
                </
    asp:DataList>
            </
    form>
        </
    body>
    </
    html

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    90
    Very interesting. I looked at my code and it pretty much matched yours. I deleted the control and re-added it to the project and it now works. Thanks for the input

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    I am using something similar...
    Code:
    <asp:HyperLink id="lnkSubject" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Subject") %>' NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ID") %>'>
    </asp:HyperLink>
    However...this puts my links as:

    2
    3
    67

    etc

    I want them to be:

    ShowComment.aspx?ID=2


    What do I add to make the link equal to this?

    Woka

  5. #5
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Code:
    <asp:HyperLink 
    	id="lnkSubject" 
    	runat="server" 
    	Text='<%# DataBinder.Eval(Container.DataItem, "Subject") %>' 
    	NavigateUrl='ShowComment.aspx?ID=<%# DataBinder.Eval(Container.DataItem, "ID") %>'>
    </asp:HyperLink>

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