Reputation: 874
I have grid , in that grid four columns are having "Data Formatting" attribute. Two columns are giving result according to "Data Formatting". But two columns are not taking the condition mention in "Data Formatting". Here we mention decimal two places value format in "Data Formatting" attribute for four columns.
Here is aspx code:
<asp:GridView ID="GridView2" runat="server" AllowPaging="true" PageSize="5"
AutoGenerateColumns="false" Width="100%" OnPageIndexChanging="GridView2_PageIndexChanging"
OnRowDataBound="GridView2_RowDataBound" CssClass="Grid">
<RowStyle CssClass="GridRow"/>
<Columns>
<asp:BoundField HeaderText="No" DataField="id" Visible="false"/>
<asp:BoundField HeaderText="Scenario" DataField="Scenario"/>
<asp:BoundField HeaderText="Type" DataField="Type"/>
<asp:BoundField HeaderText="Station Name" DataField="StationName"/>
<asp:BoundField HeaderText="Action" DataField="Action"/>
<asp:BoundField HeaderText="minH" DataField="minH"
SortExpression="minH" DataFormatString="{0:F2}"/>
<asp:BoundField HeaderText="maxH" DataField="maxH"
SortExpression="maxH" DataFormatString="{0:F2}"/>
<asp:BoundField HeaderText="Min Level" DataField="Min_OL"
SortExpression="Min_OL" DataFormatString="{0:F2}" />
<asp:BoundField HeaderText="Max Level" DataField="Max_OL"
SortExpression="Max_OL" DataFormatString="{0:F2}" />
</Columns>
<PagerStyle BackColor="White" Height="40px" Font-Bold="true" Font-
Size="Medium" ForeColor="Green" HorizontalAlign="Center"/>
<PagerSettings FirstPageText="First" LastPageText="Last"
Mode="NumericFirstLast" PageButtonCount="3" />
<HeaderStyle BackColor="#ABDB78" ForeColor="Black" Height="35px" Font-
Size="13px" Font-Names="verdana"/>
</asp:GridView>
I am also putting here code behind functions:
protected void PumpGridBind()
{
string name = Request.QueryString[1].ToString();
string query = "select q1.ID , q1.Scenario, q1.Type,
q1.StationName ,q1.MinH, q1.MaxH ,q1.Station_Id, q1.Min_OL, q1.Max_OL,
q2.Daily_Abstraction as Action from (select
SD.id,SD.Scenario,PR.Type,PR.StationName,max(if(PARAM = 'minH', Value, '
-999.00')) as 'minH',max(if(PARAM = 'maxH', Value, ' -999.00'))
as 'maxH',psd.Station_Id,psd.Min_OL,psd.Max_OL from sgwebdb.param_reference as
PR Inner join sgwebdb.scenario_data as SD ON PR.Param_Id = SD.Param_Id INNER
JOIN sgwebdb.qualicision_detail as Q ON SD.SCENARIO = Q.Alternative INNER JOIN
sgwebdb.pump_station_detail as psd ON psd.Station_Id = PR.Station_Id where
PR.Type = 'Pump' and Q.Alternative = '" + name + "' GROUP BY PR.Id) q1 JOIN
(SELECT t1.Daily_Abstraction ,t1.Station_id FROM sgwebdb.pump_station_data t1
INNER JOIN (SELECT Station_id, MAX(lastupdate) as lastupdate FROM
sgwebdb.pump_station_data GROUP BY Station_id ) t2 ON t1.Station_id =
t2.Station_id AND t1.lastupdate = t2.lastupdate) q2 on
q1.Station_Id=q2.Station_Id";
this.GridView2.DataSource = PSI.DataAccess.Database.DatabaseManager.GetConnection
().GetData(query);
GridView2.DataBind();
}
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
PumpGridBind();
}
RowDataBound Function :
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string iText = e.Row.Cells[5].Text;
if (iText == "-999.00")
{
e.Row.Cells[5].Text = "-999.00";
}
else
{
double num = Convert.ToDouble(iText);
string jText = e.Row.Cells[7].Text;
double min = Convert.ToDouble(jText);
string kText = e.Row.Cells[8].Text;
double max = Convert.ToDouble(kText);
if (num >= min && num < max)
{
//e.Row.Cells[5].CssClass = "GridCond2";
e.Row.Cells[5].ForeColor = System.Drawing.Color.Purple;
}
else if (num >= max)
{
//e.Row.Cells[5].CssClass = "GridCond1";
e.Row.Cells[5].ForeColor = System.Drawing.Color.Red;
}
else
{
//e.Row.Cells[5].CssClass = "GridCond3";
e.Row.Cells[5].ForeColor = System.Drawing.Color.Black;
}
}
}
}
for "minH" and "maxH" , it is not showing decimal two places value but "Min_OL" and "Max_OL" are showing decimal two places values. I tried DataFormatString="{0:0.00}" but that one is also not working.
Upvotes: 1
Views: 516
Reputation: 1708
Please check the source of your data - in case it is a database, ensure that SQL type is including decimals (force it by multiplying with 1.0). If other source, check the same.
You can check the type of data coming through using the following as a Template field:
<asp:TemplateField HeaderText="minH DataType">
<ItemTemplate><%#Eval("minH").GetType()%></ItemTemplate>
</asp:TemplateField>
Upvotes: 2
Reputation: 840
please try simple {0:F} Instead of {0:F2}. and also check that data format in all four values is same.
Upvotes: 0