E
E L
I am not sure how to do this. I have part of it working and I think I
understand why it isn't working.
I am dynamically placing some data into and ASP:Table from a DataSource.
I am looping through the datasource by going through the rows no problem
to display the data in cells added by rows to the asp:table. What I am
also doing though is adding a button for each row that is to run an
Access insert query that adds a record in a log table.
I have used the following code to get this to work which it does:
... this is in a loop of the DataSet
for (int i = 0; i < dsResult.Tables[0].Rows.Count - 1; i++)
{
Button btn = new Button();
btn.Text = "whatever";
intTID = dsResult.Tables[0].Rows.ItemArray[5].ToString();
intUserGroup = dsResult.Tables[0].Rows.ItemArray[6].ToString();
btn.Click += new EventHandler(this.b_Click);
tCell1.Controls.Add(btn);
etc.. etc..
}
... [assume connection open and all that stuff]
private void b_Click(object sender, EventArgs e)
{
cmd.Parameters.AddWithValue("pmSignOff", intSignOffID);
cmd.Parameters.AddWithValue("pmUserID", intUserID);
cmd.Parameters.AddWithValue("pmTableNameID", intTID);
cmd.Parameters.AddWithValue("pmGroupID", intUserGroup );
cmd.ExecuteNonQuery();
}
Here is the problem I am having. The button does display for each row,
and the query does execute and run when I press the button. The values
being passed in intTID and intUserGroup (which are local to the class
and sort of global), are suppose to be different for each row though,
and are to insert a unique table ID, and a different group depending on
what is in the dataset. Problem is it is only assigning the last
tableID from the result set into the button and will always pass that
same ID no matter what button is pressed. This is the same with the
intUserGroup.
What do I have to do differently to make sure that when the button is
created dynamically it will pass the unique values for each row?
Thanks!
understand why it isn't working.
I am dynamically placing some data into and ASP:Table from a DataSource.
I am looping through the datasource by going through the rows no problem
to display the data in cells added by rows to the asp:table. What I am
also doing though is adding a button for each row that is to run an
Access insert query that adds a record in a log table.
I have used the following code to get this to work which it does:
... this is in a loop of the DataSet
for (int i = 0; i < dsResult.Tables[0].Rows.Count - 1; i++)
{
Button btn = new Button();
btn.Text = "whatever";
intTID = dsResult.Tables[0].Rows.ItemArray[5].ToString();
intUserGroup = dsResult.Tables[0].Rows.ItemArray[6].ToString();
btn.Click += new EventHandler(this.b_Click);
tCell1.Controls.Add(btn);
etc.. etc..
}
... [assume connection open and all that stuff]
private void b_Click(object sender, EventArgs e)
{
cmd.Parameters.AddWithValue("pmSignOff", intSignOffID);
cmd.Parameters.AddWithValue("pmUserID", intUserID);
cmd.Parameters.AddWithValue("pmTableNameID", intTID);
cmd.Parameters.AddWithValue("pmGroupID", intUserGroup );
cmd.ExecuteNonQuery();
}
Here is the problem I am having. The button does display for each row,
and the query does execute and run when I press the button. The values
being passed in intTID and intUserGroup (which are local to the class
and sort of global), are suppose to be different for each row though,
and are to insert a unique table ID, and a different group depending on
what is in the dataset. Problem is it is only assigning the last
tableID from the result set into the button and will always pass that
same ID no matter what button is pressed. This is the same with the
intUserGroup.
What do I have to do differently to make sure that when the button is
created dynamically it will pass the unique values for each row?
Thanks!