|
|
|
start date: Fri, 17 Aug 2007 12:12:26 -0400,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
Mike
|
|
2
George Ter-Saakov
|
|
3
Mark Rae [MVP]
|
|
4
Göran Andersson
|
|
5
Mike
|
|
6
Mike
|
|
7
Göran Andersson
|
|
8
Mike
|
|
9
Göran Andersson
|
|
10
Mike
|
|
11
Göran Andersson
|
code working but still getting error
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an 'input string was not in a correct format.'
Code:
foreach (GridViewRow row in grid.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("checkbox");
if (chk.Checked)
{
Data= grid.DataKey[grid.RowIndex].value ";";
}
}
String[] rowValues= Data.Split(';');
foreach (string updateValues in rowValues
{
Update.UpdateUserRow(Convert.ToInt32(updateValues));
}
this is updating the record that is selected in the grid, but I'm getting the error
'input string was not in a correct format.'
any idea why?
Date:Fri, 17 Aug 2007 12:12:26 -0400
Author:
|
Re: code working but still getting error
Most likely because of the last ';' symbol.
I guess
1;2;3; ends up when you do Split as a an array of 4 elements '1', '2', '3', '' (notice empty element).
So it blows up when you try to convert it to Int32.
George.
"Mike" wrote in message news:uJ$VnlO4HHA.4584@TK2MSFTNGP03.phx.gbl...
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an 'input string was not in a correct format.'
Code:
foreach (GridViewRow row in grid.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("checkbox");
if (chk.Checked)
{
Data= grid.DataKey[grid.RowIndex].value ";";
}
}
String[] rowValues= Data.Split(';');
foreach (string updateValues in rowValues
{
Update.UpdateUserRow(Convert.ToInt32(updateValues));
}
this is updating the record that is selected in the grid, but I'm getting the error
'input string was not in a correct format.'
any idea why?
Date:Fri, 17 Aug 2007 12:43:47 -0400
Author:
|
Re: code working but still getting error
"Mike" wrote in message
news:uJ$VnlO4HHA.4584@TK2MSFTNGP03.phx.gbl...
> String[] rowValues= Data.Split(';');
String[] rowValues= Data.TrimEnd(';').Split(';');
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Fri, 17 Aug 2007 17:49:42 +0100
Author:
|
Re: code working but still getting error
Mike wrote:
> I have code that is doing some updating to a record. Its getting the ID
> to update from the Grid. I'm passing an INT to my method to update the
> record. My code is working though I'm still getting an 'input string was
> not in a correct format.'
>
>
> Code:
>
> foreach (GridViewRow row in grid.Rows)
> {
> CheckBox chk = (CheckBox)gr.FindControl("checkbox");
> if (chk.Checked)
> {
> Data+= grid.DataKey[grid.RowIndex].value + ";";
> }
> }
> String[] rowValues= Data.Split(';');
>
> foreach (string updateValues in rowValues
> {
> Update.UpdateUserRow(Convert.ToInt32(updateValues));
> }
>
> this is updating the record that is selected in the grid, but I'm
> getting the error
> 'input string was not in a correct format.'
>
>
> any idea why?
>
I assume that you only want to update each row once? With your code you
would update the first row, then your would update first row again when
the second row is updated, and so on. If ten rows are selected, you
would be updating the first of them ten times.
Just get the value and update the row:
foreach (GridViewRow row in grid.Rows) {
CheckBox chk = (CheckBox)gr.FindControl("checkbox");
if (chk.Checked) {
int value = int.Parse(grid.DataKey[grid.RowIndex].value);
Update.UpdateUserRow(value);
}
}
--
Gran Andersson
_____
http://www.guffa.com
Date:Fri, 17 Aug 2007 18:59:37 +0200
Author:
|
Re: code working but still getting error
this works for only one. I need to capture all the rows that are checked
"Gran Andersson" wrote in message
news:uEQNKAP4HHA.1484@TK2MSFTNGP06.phx.gbl...
> Mike wrote:
>> I have code that is doing some updating to a record. Its getting the ID
>> to update from the Grid. I'm passing an INT to my method to update the
>> record. My code is working though I'm still getting an 'input string was
>> not in a correct format.'
>> Code:
>> foreach (GridViewRow row in grid.Rows)
>> {
>> CheckBox chk = (CheckBox)gr.FindControl("checkbox");
>> if (chk.Checked)
>> {
>> Data+= grid.DataKey[grid.RowIndex].value + ";";
>> }
>> }
>> String[] rowValues= Data.Split(';');
>> foreach (string updateValues in rowValues
>> {
>> Update.UpdateUserRow(Convert.ToInt32(updateValues));
>> }
>> this is updating the record that is selected in the grid, but I'm
>> getting the error
>> 'input string was not in a correct format.'
>> any idea why?
>>
>
> I assume that you only want to update each row once? With your code you
> would update the first row, then your would update first row again when
> the second row is updated, and so on. If ten rows are selected, you would
> be updating the first of them ten times.
>
> Just get the value and update the row:
>
> foreach (GridViewRow row in grid.Rows) {
> CheckBox chk = (CheckBox)gr.FindControl("checkbox");
> if (chk.Checked) {
> int value = int.Parse(grid.DataKey[grid.RowIndex].value);
> Update.UpdateUserRow(value);
> }
> }
>
> --
> Gran Andersson
> _____
> http://www.guffa.com
Date:Fri, 17 Aug 2007 13:13:19 -0400
Author:
|
Re: code working but still getting error
thanks this worked
"Mark Rae [MVP]" wrote in message
news:uDdpS6O4HHA.3916@TK2MSFTNGP02.phx.gbl...
> "Mike" wrote in message
> news:uJ$VnlO4HHA.4584@TK2MSFTNGP03.phx.gbl...
>
>> String[] rowValues= Data.Split(';');
>
> String[] rowValues= Data.TrimEnd(';').Split(';');
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
Date:Fri, 17 Aug 2007 13:14:59 -0400
Author:
|
Re: code working but still getting error
Mike wrote:
> this works for only one. I need to capture all the rows that are checked
> "Gran Andersson" wrote in message
> news:uEQNKAP4HHA.1484@TK2MSFTNGP06.phx.gbl...
What do you mean? You are looping through the rows, you don't have to
repeat all the updates for every new row you find.
I realise now that your code is even worse than I first thought. You're
not only repeating the first update for every subsequent selected row,
but repeating it for every subsequent row regardless if it's selected or
not. If you have a hundred row and select the first one to be updated,
it will be updated a hundred times!
--
Gran Andersson
_____
http://www.guffa.com
Date:Fri, 17 Aug 2007 19:59:21 +0200
Author:
|
Re: code working but still getting error
Actually I got it working with my code.
Once I added Mark's suggestion, it works just fine.
String[] rowValues= Data.TrimEnd(';').Split(';');
"Gran Andersson" wrote in message
news:%23cUzjhP4HHA.5804@TK2MSFTNGP05.phx.gbl...
> Mike wrote:
>> this works for only one. I need to capture all the rows that are checked
>> "Gran Andersson" wrote in message
>> news:uEQNKAP4HHA.1484@TK2MSFTNGP06.phx.gbl...
>
> What do you mean? You are looping through the rows, you don't have to
> repeat all the updates for every new row you find.
>
> I realise now that your code is even worse than I first thought. You're
> not only repeating the first update for every subsequent selected row, but
> repeating it for every subsequent row regardless if it's selected or not.
> If you have a hundred row and select the first one to be updated, it will
> be updated a hundred times!
>
> --
> Gran Andersson
> _____
> http://www.guffa.com
Date:Fri, 17 Aug 2007 14:05:19 -0400
Author:
|
Re: code working but still getting error
Mike wrote:
> Actually I got it working with my code.
>
> Once I added Mark's suggestion, it works just fine.
>
> String[] rowValues= Data.TrimEnd(';').Split(';');
Yes, it's working, but you are doing a tremendous amount of work totally
needlessly.
It's like setting the values 1 to 100 in an array as:
int[] num = new int[100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j <= i; j++) {
num[j] = j + 1;
}
}
--
Gran Andersson
_____
http://www.guffa.com
Date:Fri, 17 Aug 2007 21:21:37 +0200
Author:
|
Re: code working but still getting error
I could have 1 selected or 1000 selected, so the update needs to take place
for each row that is selected and the way you suggested only works for one
row, thats it. what happens if the user selects all rows, or 5 rows?
"Gran Andersson" wrote in message
news:ug02gPQ4HHA.3684@TK2MSFTNGP02.phx.gbl...
> Mike wrote:
>> Actually I got it working with my code.
>>
>> Once I added Mark's suggestion, it works just fine.
>>
>> String[] rowValues= Data.TrimEnd(';').Split(';');
>
> Yes, it's working, but you are doing a tremendous amount of work totally
> needlessly.
>
> It's like setting the values 1 to 100 in an array as:
>
> int[] num = new int[100];
> for (int i = 0; i < 100; i++) {
> for (int j = 0; j <= i; j++) {
> num[j] = j + 1;
> }
> }
>
> --
> Gran Andersson
> _____
> http://www.guffa.com
Date:Fri, 17 Aug 2007 15:39:45 -0400
Author:
|
Re: code working but still getting error
Mike wrote:
> I could have 1 selected or 1000 selected, so the update needs to take place
> for each row that is selected and the way you suggested only works for one
> row, thats it. what happens if the user selects all rows, or 5 rows?
>
It's looping all the rows, why do you think that it only works for one row?
You only have to update each row once. You don't have to update each row
hundreds or thousands of times.
--
Gran Andersson
_____
http://www.guffa.com
Date:Sat, 18 Aug 2007 03:00:57 +0200
Author:
|
|
|