Last post May 27, 2010 11:46 AM by 3houd
May 23, 2010 09:05 AM|3houd|LINK
If I have a GridView with 4 columns
three of them displaying different prices of the same product
and the fourth one should display the cheapest..
how can I compare the values of the columns ??
I use c#
May 23, 2010 09:39 AM|adeelehsan|LINK
I am assuming that you have 3 columns in the database table for the 3 prices. i.e
price1, price2, price3 and you are using a select statement to fetch them and bind with the gridview.
Then use the following code in the RowDataBound event:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
//find minimum value
if (e.Row.RowIndex >= 0)//if row is not the heading row
int p1, p2, p3, min;
p1 = Convert.ToInt32(e.Row.Cells.Text);
p2 = Convert.ToInt32(e.Row.Cells.Text);
p3 = Convert.ToInt32(e.Row.Cells.Text);
min = p1;
if (min > p2)
min = p2;
if (min > p3)
min = p3;
e.Row.Cells.Text = min.ToString();
asp .net 2. 0
May 23, 2010 06:20 PM|superguppie|LINK
p1 = DataBinder.Eval(e.Row.DataItem, "price1");
May 24, 2010 08:26 PM|3houd|LINK
I applied the code but this message appears:
Input string was not in a correct format
May 25, 2010 06:36 AM|adeelehsan|LINK
Make sure that you are reading the right cell value. In my code, I am assuming that you are only displaying 4 colulmns. 3 of them are prices and 4th is the chepeast value. So the index number ranges from 0 to 3.
You might need to change these index number in your case because you might have different arrangement of data in the gridview.
May 27, 2010 11:46 AM|3houd|LINK
it worked ^_^