Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

ImageButton loses CommandArgument

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bigloopy - 04 Apr 2008 15:40 GMT
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.
George Ter-Saakov - 04 Apr 2008 16:09 GMT
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','<%#Eval("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','<%#Eval("ID")%>')">Click
Me </a>
will be
<a
href="javascript:__doPostBack('<%=LinkButton1.ClientID%>','<%#Eval("ID")%>')">Click
Me </a>

Good luck.
George.

>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
[quoted text clipped - 19 lines]
> row
> of data.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.