473,609 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help converting GridViewCommand EventArg 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, GridViewCommand EventArgs e)
{
int rowIndex = Convert.ToInt32 (e.CommandArgum ent);

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.FormatEx ception: 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.CommandArgum ent);
Line 110: // Retrieve the row that contains the button clicked
Line 111: // by the user from the Rows collection.
Source File: c:\local_websit es\btm_root\Use rControls\Rem.a scx.cs Line:
109

Stack Trace:
[FormatException : Input string was not in a correct format.]
System.Number.S tringToNumber(S tring str, NumberStyles options,
NumberBuffer& number, NumberFormatInf o info, Boolean parseDecimal) +2753539
System.Number.P arseInt32(Strin g s, NumberStyles style, NumberFormatInf o
info) +102
System.String.S ystem.IConverti ble.ToInt32(IFo rmatProvider provider) +43
System.Convert. ToInt32(Object value) +25
UserControls_Re m.grid_RowComma nd(Object sender, GridViewCommand EventArgs
e) in c:\local_websit es\btm_root\Use rControls\Rem.a scx.cs:109
System.Web.UI.W ebControls.Grid View.OnRowComma nd(GridViewComm andEventArgs
e) +96
System.Web.UI.W ebControls.Grid View.HandleEven t(EventArgs e, Boolean
causesValidatio n, String validationGroup ) +121
System.Web.UI.W ebControls.Grid View.OnBubbleEv ent(Object source, EventArgs
e) +162
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +56
System.Web.UI.W ebControls.Grid ViewRow.OnBubbl eEvent(Object source,
EventArgs e) +118
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +56
System.Web.UI.W ebControls.Imag eButton.OnComma nd(CommandEvent Args e) +106
System.Web.UI.W ebControls.Imag eButton.RaisePo stBackEvent(Str ing
eventArgument) +200
System.Web.UI.W ebControls.Imag eButton.System. Web.UI.IPostBac kEventHandler.R aisePostBackEve nt(String
eventArgument) +31
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +72
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3839


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

Keith

"keithb" <kb******@dslex treme.com> wrote in message
news:eT******** ******@TK2MSFTN GP03.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, GridViewCommand EventArgs e)
{
int rowIndex = Convert.ToInt32 (e.CommandArgum ent);

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.FormatEx ception: 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.CommandArgum ent);
Line 110: // Retrieve the row that contains the button clicked
Line 111: // by the user from the Rows collection.
Source File: c:\local_websit es\btm_root\Use rControls\Rem.a scx.cs Line:
109

Stack Trace:
[FormatException : Input string was not in a correct format.]
System.Number.S tringToNumber(S tring str, NumberStyles options,
NumberBuffer& number, NumberFormatInf o info, Boolean parseDecimal)
+2753539
System.Number.P arseInt32(Strin g s, NumberStyles style, NumberFormatInf o
info) +102
System.String.S ystem.IConverti ble.ToInt32(IFo rmatProvider provider) +43
System.Convert. ToInt32(Object value) +25
UserControls_Re m.grid_RowComma nd(Object sender, GridViewCommand EventArgs
e) in c:\local_websit es\btm_root\Use rControls\Rem.a scx.cs:109
System.Web.UI.W ebControls.Grid View.OnRowComma nd(GridViewComm andEventArgs
e) +96
System.Web.UI.W ebControls.Grid View.HandleEven t(EventArgs e, Boolean
causesValidatio n, String validationGroup ) +121
System.Web.UI.W ebControls.Grid View.OnBubbleEv ent(Object source,
EventArgs e) +162
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args)
+56
System.Web.UI.W ebControls.Grid ViewRow.OnBubbl eEvent(Object source,
EventArgs e) +118
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args)
+56
System.Web.UI.W ebControls.Imag eButton.OnComma nd(CommandEvent Args e) +106
System.Web.UI.W ebControls.Imag eButton.RaisePo stBackEvent(Str ing
eventArgument) +200

System.Web.UI.W ebControls.Imag eButton.System. Web.UI.IPostBac kEventHandler.R aisePostBackEve nt(String
eventArgument) +31
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +72
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3839

Jun 6 '06 #2

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

Similar topics

0
1554
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 know the syntax to databind the commandargument to the row through code. I am assumning I use the DataBinder.Eval method but I cannot get it going. Below is the code sample. Thanks Solomon public class KnowlagentDataGridTemplate : ITemplate
5
7271
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 Button_Click procedure does not retrieve the value of the textbox where the button was clicked. Thanks in Advance,
2
2189
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): <asp:DataList id="dtl1" runat="server"
1
3164
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" OnCommand="lnkButtonClick" enableviewstate="False" CssClass="Detail" Text="Text" runat="server"></asp:LinkButton>
2
4937
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 UI Dim arg As String = sender.CommandArgument is the code from: http://www.4guysfromrolla.com/webtech/082901-1.2.shtml
2
6022
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
13298
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...
7
5327
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 date System.out.println(string_dob); s.Info_DOB=Date.valueOf(string_dob); runs perfectly fine in the method insert() and throws up an illegal Exception in the method UPDATE.This is the error I get when I pass a date "1979-05-02"
9
1408
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. But I'm not sure how to approach this. How would I tell the target page which user to display? I'd prefer not to pass the user's ID on the URL, and I don't know when I'd get a chance to set a Session variable.
0
8406
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
7002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5510
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
4021
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2531
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
1
1672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1389
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.