A
Andrew Banks
I've got the following code as part of a C# web form but am having problems
calling a command. I create a dataset and put some data on the screen. This
works fine. (relevant sample below)
foreach (DataRow row in ds.Tables["Orders"].Rows)
{
detailsbtn = new LinkButton();
//Assign a unique ID to the details control
detailsbtn.ID = "details" + row["OrderID"].ToString().Replace("-",
String.Empty);
detailsbtn.Text =
DateTime.Parse(row["OrderDate"].ToString()).ToShortDateString()+" - No.
"+row["OrderNumber"].ToString()+" from user " +row["UserName"].ToString();
detailsbtn.CommandArgument = row["OrderID"].ToString();
detailsbtn.Command += new CommandEventHandler(OnViewDetails);
// Add the controls
phOrders.Controls.Add(detailsbtn);
phOrders.Controls.Add(new LiteralControl("<br>"));
}
I then have the following for the OnViewDetails handler. When I click one of
the LinkButtons created in the above code, this handler should be called but
it doesn't seem to be calling it. It simply posts back to the page but
doesn't set the text of the label.
private void OnViewDetails(Object sender, CommandEventArgs e)
{
this.lblMessage.Text = "Button has been pressed";
}
As this is part of a bigger page, I've uploaded the aspx and cs files to
http://andrew-banks.co.uk/problem.zip if people need access to the full code
in order to help.
Thanks in advance,
Andrew
calling a command. I create a dataset and put some data on the screen. This
works fine. (relevant sample below)
foreach (DataRow row in ds.Tables["Orders"].Rows)
{
detailsbtn = new LinkButton();
//Assign a unique ID to the details control
detailsbtn.ID = "details" + row["OrderID"].ToString().Replace("-",
String.Empty);
detailsbtn.Text =
DateTime.Parse(row["OrderDate"].ToString()).ToShortDateString()+" - No.
"+row["OrderNumber"].ToString()+" from user " +row["UserName"].ToString();
detailsbtn.CommandArgument = row["OrderID"].ToString();
detailsbtn.Command += new CommandEventHandler(OnViewDetails);
// Add the controls
phOrders.Controls.Add(detailsbtn);
phOrders.Controls.Add(new LiteralControl("<br>"));
}
I then have the following for the OnViewDetails handler. When I click one of
the LinkButtons created in the above code, this handler should be called but
it doesn't seem to be calling it. It simply posts back to the page but
doesn't set the text of the label.
private void OnViewDetails(Object sender, CommandEventArgs e)
{
this.lblMessage.Text = "Button has been pressed";
}
As this is part of a bigger page, I've uploaded the aspx and cs files to
http://andrew-banks.co.uk/problem.zip if people need access to the full code
in order to help.
Thanks in advance,
Andrew