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

CommandArgument does not contain index when under Templatefield??

CommandArgument does not contain row index when command under
Templatefield of- Gridview

It appears CommandArgument passed to the rowcommand event does not
contain row index when the command is called from a control under a
Templatefield. Why is this not the case when the command is from a
Buttonfield for example. And, if this so, how can I get the index of
the row executing the command. This code works for Buttonfield under
the rowcommand event, but fails for Templatefield buttons under the
same gridview.


Dim grid As GridView = CType(sender, GridView)
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = grid.Rows(index)

Feb 14 '07 #1
1 6716
ButtonField does this internally, e.g it contains literally a Button which
has CommandArgument set to the index of the row, and when clicked, the
Command event is bubbled up to the GridViewRow and finally to the GridView,
which raises RowCommand as response to this action.

With TemplateField, you take the customization route and framework cannot do
everything automatically. Since you provide the content on the template, you
are responsible for passing what you need to pass. Framework is responsible
for instantisting the correct template (and setting controls in it as child
control of the relevant GridViewRow). Besides, RowCommand couldn't be raised
from TemplateField, unless there is a command-capable controls (any of the
Buttons), so it's something that isn't done automatically.

To get the index, get it from current Row's RowIndex property, for example
in RowCreated event, or you can also access it in databinding syntax when
you refer to Container (which references current GridViewRow).
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"jobs" <jo**@webdos.comwrote in message
news:11*********************@a75g2000cwd.googlegro ups.com...
CommandArgument does not contain row index when command under
Templatefield of- Gridview

It appears CommandArgument passed to the rowcommand event does not
contain row index when the command is called from a control under a
Templatefield. Why is this not the case when the command is from a
Buttonfield for example. And, if this so, how can I get the index of
the row executing the command. This code works for Buttonfield under
the rowcommand event, but fails for Templatefield buttons under the
same gridview.


Dim grid As GridView = CType(sender, GridView)
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = grid.Rows(index)
Feb 14 '07 #2

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

Similar topics

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: Benjamin Joldersma | last post by:
Hello all, My basic problem is that my LinkButton does not support a data bound CommandArgument property under certain cases. The intent is to filter my datagrid based on a specific row's...
2
by: needin4mation | last post by:
I have some VB.NET code that I am trying to convert. I'm not sure what to do here and was hoping you could help. Sub PagerButtonClick(sender As Object, e As EventArgs) 'used by external paging...
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...
0
by: ssims | last post by:
I've got a GridView that's sorted by a stored procedure with ROW_NUMBER: PROCEDURE dbo.GetCalendarsByStatusIDPaged ( @startRowIndex int, @maximumRows int, @statusID int ) AS
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...
3
by: shyamal123 | last post by:
I am write a function in javascript ie function rowcolor(obj) { obj.parentelement.parentelement.style.backgroundcolor='yellow' ; } when i run the appln the error is occure ie the...
1
by: Leon Mayne | last post by:
Hello, I have a gridview that's bound to a generic list of business objects and am using the RowCommand event to capture user clicks on actions. This was working fine up until today, but now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
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...

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.