473,792 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Fi ndControl("btnM ainMoveDown"), Button).Command Argument =
CStr(CType(Me.d atMain.DataSour ce, DataTable).Rows (e.Item.ItemInd ex +
1)("id"))
I have tried using a System.Diagnost ics.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.CommandArgume nt
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********@hotm ail.com
http://www.nathansokalski.com/
May 27 '07 #1
1 4609
On May 27, 6:00 am, "Nathan Sokalski" <njsokal...@hot mail.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.Fi ndControl("btnM ainMoveDown"), Button).Command Argument =
CStr(CType(Me.d atMain.DataSour ce, DataTable).Rows (e.Item.ItemInd ex +
1)("id"))

I have tried using a System.Diagnost ics.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.CommandArgume nt
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...@hotm ail.comhttp://www.nathansokal ski.com/
Hi Nathan

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

CType(e.Item.Fi ndControl("btnM ainMoveDown"), Button).Command Argument =
CStr(CType(Me.d atMain.DataSour ce, DataTable).Rows (e.Item.ItemInd ex + 1)
("id"))
Response.Write( CType(e.Item.Fi ndControl("btnM ainMoveDown"),
Button).Command Argument)

Another thought: are you sure about e.Item.ItemInde x + 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
4839
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 the background of the td to be different for the currently selected linkbutton than for the other linkbuttons:
8
2842
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 columns to the datagrid - for all records. I tried getting a reference to the datagrid like this:
4
6205
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 has been done. But I can't set HeaderText property of DataGridColumn in prerender because it is evaluated during data binding. I don't want to call DataBind() in OnPreRender also... Any ideas? I've tried to walk through Controls collection in...
2
3047
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 knowing the value associated with the row? Is there a different property or a hack i can use? Thanks,
2
2671
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 can't see why. can anyone tell me why this chunk of code works: <asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 136px" runat="server" CellPadding="3" OnItemDataBound="DataGridBindEvent"...
6
7108
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 datagrid1.columns(1).width = 1000 Except that there is no such things as a columns collection in a datagrid.
1
6151
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) { int rowIndex = Convert.ToInt32(e.CommandArgument); When this code runs it triggers an "Input string was not in a correct format" error.
2
6029
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 fine. However, e.CommandArgument is an empty string, presumably because the CommandArgument property of the ImageButtons is not set. Is there some way, in the markup, to set the CommandArgument to the row index? <ItemTemplate>
1
13309
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 ImageButton I needed to redirect the user to the Edit page where the data on the page would be prepopulated with data from the database. I tried several things without success then discovered that the CommandArgument property could be used for this...
0
9517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.