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

Need help converting GridViewCommandEventArg CommandArgument to an integer

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.

According to Microsoft documentation, the rowindex value is an integer, so I
do not know how to troublshoot this problem. Can someone offer a suggestion?

Thanks,

Keith

PS Here is the error message with stack trace info in case that is useful:

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:
Line 107: // Convert the row index stored in the CommandArgument
Line 108: // property to an Integer.
Line 109: int rowIndex = Convert.ToInt32(e.CommandArgument);
Line 110: // Retrieve the row that contains the button clicked
Line 111: // by the user from the Rows collection.
Source File: c:\local_websites\btm_root\UserControls\Rem.ascx.c s Line:
109

Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2753539
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo
info) +102
System.String.System.IConvertible.ToInt32(IFormatP rovider provider) +43
System.Convert.ToInt32(Object value) +25
UserControls_Rem.grid_RowCommand(Object sender, GridViewCommandEventArgs
e) in c:\local_websites\btm_root\UserControls\Rem.ascx.c s:109
System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
e) +96
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +121
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source, EventArgs
e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.ImageButton.OnCommand(Co mmandEventArgs e) +106
System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument) +200
System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839


Jun 6 '06 #1
1 6129
Replying to my own question for the benefit of other newbies: It turns out
that the example I was following was wrong. GridViewCommandEventArgs does
not contain row index information. It is necessary to pass identifying
information as a CommandArgument.

Keith

"keithb" <kb******@dslextreme.com> wrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
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.

According to Microsoft documentation, the rowindex value is an integer, so
I do not know how to troublshoot this problem. Can someone offer a
suggestion?

Thanks,

Keith

PS Here is the error message with stack trace info in case that is useful:

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a
correct format.

Source Error:
Line 107: // Convert the row index stored in the CommandArgument
Line 108: // property to an Integer.
Line 109: int rowIndex = Convert.ToInt32(e.CommandArgument);
Line 110: // Retrieve the row that contains the button clicked
Line 111: // by the user from the Rows collection.
Source File: c:\local_websites\btm_root\UserControls\Rem.ascx.c s Line:
109

Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
+2753539
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo
info) +102
System.String.System.IConvertible.ToInt32(IFormatP rovider provider) +43
System.Convert.ToInt32(Object value) +25
UserControls_Rem.grid_RowCommand(Object sender, GridViewCommandEventArgs
e) in c:\local_websites\btm_root\UserControls\Rem.ascx.c s:109
System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
e) +96
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +121
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
EventArgs e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+56
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+56
System.Web.UI.WebControls.ImageButton.OnCommand(Co mmandEventArgs e) +106
System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument) +200

System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839

Jun 6 '06 #2

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

Similar topics

0
by: Solomon Shaffer | last post by:
I have a datagrid that I am adding a template column to (containing a couple of linkbuttons) at runtime and am having some difficulty setting the commandargument or the linkbuttons. Does anyone...
5
by: Darren Smith | last post by:
Hi There, I have a shopping cart app that displays products along with a textbox (to enter quantity) and an image button to add the item to the shopping cart. Please explain why my below...
2
by: News | last post by:
Hi, I need help with datalist and linkbutton. I need a LinkButton to display in datalist if datafield "is_measure_customchecklist" in a db table set to true. Here is the code (in parts): ...
1
by: Fabrice | last post by:
Hello Is it possible to modify CommandArgument property of a LinkButton from vb class (code behind). So, this is my control in my .aspx page : <asp:LinkButton id="strTd"...
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...
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...
7
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to...
9
by: Jonathan Wood | last post by:
Greetings, My app displays users in a GridView control. I'd like to have the name field shown in each row of this control a link that displays another page with information about that user. ...
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.