Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Using Datagridview control the below code has been written now I want to write the same code using gridview asp.net.

What I have tried:

<pre>nt amount = Convert.ToInt32(textBox1.Text.Trim());
for (int i = 2; i < dgv.Columns.Count; i++)
{
foreach (DataGridViewRow row in dgv.Rows)
{
int value = Convert.ToInt32(row.Cells[i].Value);
if (amount >= value)
amount = amount - value;
else if (amount == 0)
row.Cells[i].Value = amount;
else
{
row.Cells[i].Value = amount;
amount = 0;
}
}
}
if (amount > 0)
{
MessageBox.Show("Please check the amount");
}
Posted
Updated 19-Jan-21 22:19pm

You need to rethink your whole approach: that won't work, and wouldn't be suitable if it did.

Winforms and web based codes are very different: the latter is a client/server based environment in which C# code never runs on the client machine, so anything that interacts with the user needs to be in browser based code - i.e. javascript - not C#. In particular, using MessageBox won't work (except in development when both client and server are running on the same machine) and input validation needs to be done local to the client rather than at the server.

And frankly, that code is really poor quality - I don't know where you found it, but I'd put it right back and never go there again ...
 
Share this answer
 
Comments
Maciej Los 20-Jan-21 4:09am    
5ed!
OriginalGriff is right.

I'd suggest to start here: ASP.NET tutorials | Microsoft Docs[^].

You need to write ASP.NET application from scratch.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900