473,387 Members | 1,553 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,387 software developers and data experts.

ImageButton loses CommandArgument

I have a datagrid which I am adding BoundColumns to it programatically.
Tehre are already 5 columns defined in the aspx as template columns, two link
buttons and two image buttons. The datagrid should dsiplay the two link
buttons, then the dynamically generated bound columns, then the 3 image
buttons. The problem is when I insert the BoundColumns into the grid using
the DataGrid.AddAt function I lose the databinding on the CommandArgument of
the image buttons when capturing the OnCommand event. The explictly
instantiated command however does keep its value.

The sender and CommandEventArgs are almost useless to me at this point, it
is supopsed to contain the ID of the row of data it represents. If I could
get the number iof the row in terms of the datagrid I could work around it by
using the DataKeys collection. DO I need to do something special in the
databinding or viewstate? One way or another I need to figure out which row
I clicked on, either in context of the data grid itself or the ID of the row
of data.
Apr 4 '08 #1
1 2441
I feel your pain :)

Here is the way I do it

1. Drop somewhere on a page a LinkButton (let say with id = LinkButton1),
wire up Click event to LinkButton1_OnClick
2. Make a Text property empty... We do not want to see that LinkButton. It's
a decoy to generate Click event

3. In every row of your datagrid instead of button have it like this
<input type="button" OnClick="__doPostBack('LinkButton1','<%#Eval("ID") %>')"
>
NOTE: not a server control. Just plain html. you can have a link if you want
to..
like <a
href="javascript:__doPostBack('LinkButton1','<%#Ev al("ID")%>')">Click Me
</a>

4. in LinkButton1_OnClick get the row ID by reading __EVENTARGUMENT
int iRowId = Int32.Parse(Request.Form["__EVENTARGUMENT"]);
PS: code is simplified to make it clear.
In reality you will need to use LinkButton1.ClientID instead of hardcoded
value 'LinkButton1'

So <a href="javascript:__doPostBack('LinkButton1','<%#Ev al("ID")%>')">Click
Me </a>
will be
<a
href="javascript:__doPostBack('<%=LinkButton1.Clie ntID%>','<%#Eval("ID")%>')">Click
Me </a>
Good luck.
George.

"Bigloopy" <Bi******@discussions.microsoft.comwrote in message
news:8F**********************************@microsof t.com...
>I have a datagrid which I am adding BoundColumns to it programatically.
Tehre are already 5 columns defined in the aspx as template columns, two
link
buttons and two image buttons. The datagrid should dsiplay the two link
buttons, then the dynamically generated bound columns, then the 3 image
buttons. The problem is when I insert the BoundColumns into the grid
using
the DataGrid.AddAt function I lose the databinding on the CommandArgument
of
the image buttons when capturing the OnCommand event. The explictly
instantiated command however does keep its value.

The sender and CommandEventArgs are almost useless to me at this point, it
is supopsed to contain the ID of the row of data it represents. If I
could
get the number iof the row in terms of the datagrid I could work around it
by
using the DataKeys collection. DO I need to do something special in the
databinding or viewstate? One way or another I need to figure out which
row
I clicked on, either in context of the data grid itself or the ID of the
row
of data.

Apr 4 '08 #2

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

Similar topics

1
by: Darren Clark | last post by:
I need to be able to send through 2 peices of infomraiton in the commandArgument property of a image button... <asp:imagebutton CommandArgument='<%# DataBinder.Eval(Container,"DataItem."+...
1
by: Gilles T. | last post by:
Hi, I need to passing parameters in CommandArgument of the asp:ImageButton. I don't use datagrid or datalist Here is my code: Private Sub ImageButtonCommandHandler( sender As Object, e As...
2
by: Chuck Hartman | last post by:
I've been trying to add an ImageButton object to a Calendar table cell, but so far I am unable to handle the Command event from that button in my form's code behind. Below is an example of what I...
4
by: angus | last post by:
Dear all, I know that i can add a button with oncommand event "ImageButton_Command" by using the asp:ImageButton tag in the aspx code. <asp:ImageButton id="imagebutton1" runat="server"...
0
by: Oddball | last post by:
I have set up a page with uses two lots of image buttons, one for a collection and one for more images from that collection. I generate all the image buttons on page init (I know, but I...
5
by: David Lozzi | last post by:
Howdy, New to .Net 2.0 and I'm about to go back to 1.1! So many little changes are driving me nuts. I have an ImageButton in a GridView template column. When clicking the image, it should send...
1
by: Cem | last post by:
Hi, in GridView1 I have following code: <ItemTemplate> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# Eval("airport_active", "images/icons/ico_airport_active_{0}.gif") %>'...
4
by: suzanne.boyle | last post by:
Hi, I'm adding an ImageButton as a child to a custom web control and attaching an event handler to it. When the page posts back the event is not being fired however. I initially assumed I had...
0
by: Adam Right | last post by:
Hi All, i am using CommandArgument of imagebutton in a Repeater for adding a item to shopping basket, like that; ************************** <asp:Repeater ID="Repeater1" runat="server"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.