473,396 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting the CommandArgument property in the ItemDataBound event

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.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
May 27 '07 #1
1 4588
On May 27, 6:00 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
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.
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/
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("btnMainMo veDown"),
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

May 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gil | last post by:
Hello, I use VB.NET and have a series of linkbuttons that are inside individual <td>s. Like this: <td background="image.gif"><asp:linkbutton id="myID" runat="server"/></td> I would like...
8
by: Nevyn Twyll | last post by:
I have a multi-level datalist setup: DataList1 DataList2 MyGrid I have columns explicitly defined for the grid in the html. Sometimes, On the initial Load() of the Page, I want to add extra...
4
by: Adam Boczek | last post by:
I've a dropdownlist control to change language on my page. Because of page lifetime, I have to set all my labels, texts etc. from ResourceManager in prerender handler to be sure that culture change...
2
by: charliewest | last post by:
In the datagrid ButtonColumn, for both the pressButton and linkButton, there is no CommandArgument property. My question is: How do i go about programming events using the commandName without...
2
by: jason | last post by:
i'm trying to set the commandargument property of a buttoncolumn in the DataGrid ItemBind event. it works fine in one instance, but in the latest page i've written it doesn't seem to work, and i...
6
by: cr113 | last post by:
I'm trying to set the column widths for a datagrid. You'd think it would be easy. I looked it up in google and the first thing I found looked promising: datagrid1.columns(0).width = 2000...
1
by: keithb | last post by:
I have a command button in GridView row that fires the RowCommand Event when clicked. The event handler looks like this: protected void grid_RowCommand(Object sender, GridViewCommandEventArgs e)...
2
by: David | last post by:
I have a template field in a GridView that contains two ImageButtons. When the user clicks one of the buttons, the GridView's RowCommand event is fired and I can get the CommandName. All that is...
1
nateraaaa
by: nateraaaa | last post by:
While working on a recent project I discovered how useful the CommandArgument property can be. I needed to determine the record_id of a row displayed in my datagrid. When the user clicked the Edit...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.