Setting the CommandArgument property in the ItemDataBound event

N

Nathan Sokalski

I am trying to set the CommandArgument property of a Button control from a
template in a DataList of mine using code in the ItemDataBound event.
However, it does not want to set the property (it is acting as if I did not
set it). Here is my code that sets the CommandArgument property in the
ItemDataBound event:

CType(e.Item.FindControl("btnMainMoveDown"), Button).CommandArgument =
CStr(CType(Me.datMain.DataSource, DataTable).Rows(e.Item.ItemIndex +
1)("id"))


I have tried using a System.Diagnostics.Debug.Write() statement to make sure
the value I am assigning to the CommandArgument is returning the expected
value, and it is. However, when I try to use the CommandArgument property
through EventBubbling in the ItemCommand event, the e.CommandArgument
property has no value. If I set the CommandArgument attribute in the *.aspx
file as an attribute, it has a value, but I need to set it in the
ItemDataBound event. Am I doing something wrong when setting the property?
Why is the property not getting set? Thanks.
 
G

Guest

I am trying to set the CommandArgument property of a Button control from a
template in a DataList of mine using code in the ItemDataBound event.
However, it does not want to set the property (it is acting as if I did not
set it). Here is my code that sets the CommandArgument property in the
ItemDataBound event:

CType(e.Item.FindControl("btnMainMoveDown"), Button).CommandArgument =
CStr(CType(Me.datMain.DataSource, DataTable).Rows(e.Item.ItemIndex +
1)("id"))

I have tried using a System.Diagnostics.Debug.Write() statement to make sure
the value I am assigning to the CommandArgument is returning the expected
value, and it is. However, when I try to use the CommandArgument property
through EventBubbling in the ItemCommand event, the e.CommandArgument
property has no value. If I set the CommandArgument attribute in the *.aspx
file as an attribute, it has a value, but I need to set it in the
ItemDataBound event. Am I doing something wrong when setting the property?
Why is the property not getting set? Thanks.

Hi Nathan

try to see if the control was properly found and a value assigned

CType(e.Item.FindControl("btnMainMoveDown"), Button).CommandArgument =
CStr(CType(Me.datMain.DataSource, DataTable).Rows(e.Item.ItemIndex + 1)
("id"))
Response.Write(CType(e.Item.FindControl("btnMainMoveDown"),
Button).CommandArgument)

Another thought: are you sure about e.Item.ItemIndex + 1? I think, the
last row will not have a value.

Anyway, try to Response.Write at first
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top