我有网格,在该网格中有四列具有“数据格式”属性。两列根据“数据格式”给出结果。但是在“数据格式”中没有提到两栏。这里我们在四栏中的“数据格式”属性中提到小数点后两位值格式。Gridview DataFormatingString不适用于某些列
下面是ASPX代码:后面的功能
<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>
我也把这里代码:
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功能:
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;
}
}
}
}
为 “胡志明市” 和 “MAXH” ,它不显示小数点后两位值,但“Min_OL”和“Max_OL”显示小数点后两位值。 我试过DataFormatString =“{0:0.00}”,但那个也不起作用。
你检查你在胡志明市(MAXH)和Min_OL(Max_OL)的情况下提供输入相同。 ?(每种情况下都是十进制) – 2014-09-11 03:15:14
@AshokRathod在这两种情况下的数据类型都是双重的 – vim 2014-09-11 03:20:07