Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input string was not in a correct format.

Status
Not open for further replies.

daughtd

Programmer
Sep 6, 2006
15
US
I have a datatable that I'm using as a shopping cart. I need to be able to remove rows from this datatable. I have an aspx page that displays the datatables contents and I have a button which I want the user to be able to click to remove that particular record. The button's CommandParameter is set to one of the other column's databound field. When the remove button is clicked I get the following error: "Input string was not in a correct format." My method is as follows:

protected void Button1_Click(object sender, EventArgs e)
{

int index = int.Parse(e.ToString());
DataTable tempTable = new DataTable();
tempTable = (DataTable)Session["Cart"];
tempTable.Rows[index].Delete();
Session["Cart"] = tempTable;
}
Thanks in advance.
 
Which line do you get the error on?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Oops Sorry. I get the error on the following line:

int index = int.Parse(e.ToString());
 
What is the value of "e.ToString" when you step through the code?
 
When you click the button the EventArgs e contains 3 items:
Positional values X and Y along with which button has been clicked.
e.ToString() will return: {X = 55 Y = 13 Button = Left}.
So what actually you want to parse of this?

Sharing the best from my side...

--Prashant--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top