|
-
Feb 26th, 2004, 02:36 PM
#1
Thread Starter
Lively Member
*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.
-
Feb 26th, 2004, 08:34 PM
#2
Hyperactive Member
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 dt, string id)
{
DataRow row = dt.NewRow();
row["id"] = id;
dt.Rows.Add(row);
}
protected void dlTest_ItemCommand(object sender, DataListCommandEventArgs 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>
-
Feb 27th, 2004, 01:58 PM
#3
Thread Starter
Lively Member
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
-
Sep 8th, 2004, 04:54 AM
#4
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
-
Sep 10th, 2004, 07:01 PM
#5
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|