我正在尝试在网格中应用BoundField列的DataFormatString属性。我正在从后面的代码执行此操作,因为我希望DataFormatString值可配置。
我已将它应用于我的应用程序的其他页面中的某些网格上。
但是我无法找到它在我的页面中不适用于此网格的原因,这与其他页面中的网格相同。
这是我的aspx
<asp:GridView ID="GridViewYearWiseData" runat="server" CellPadding="2" AllowSorting="false"
SkinID="GridviewSkin" ViewStateMode="Enabled" ShowHeader="True" AutoGenerateColumns="false"
AllowPaging="false" Width="250px" Height="99%" GridLines="None"
ShowFooter="false" EmptyDataText="No Data Found."
ShowHeaderWhenEmpty="True" HeaderStyle-Height="30px" RowStyle-Height="25px" OnDataBound="GridViewYearWiseData_DataBound" OnSelectedIndexChanged="GridViewYearWiseData_SelectedIndexChanged"
BorderStyle="None">
<Columns>
<asp:TemplateField HeaderText="Duration" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="LinkButtonRange" runat="server" Text='<%# Eval("Duration") %>' CommandName="Select"> </asp:LinkButton>
<input type="hidden" id="FromMonth" value='<%# Eval("FromMonth") %>' runat="server" />
<input type="hidden" id="ToMonth" value='<%# Eval("ToMonth") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="value1" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80px" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="value2" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80px" HeaderStyle-HorizontalAlign="Center" />
</Columns>
<HeaderStyle HorizontalAlign="Center" />
<PagerSettings FirstPageText="First" LastPageText="Last" Mode="NextPreviousFirstLast" NextPageText="Next" PageButtonCount="4" PreviousPageText="Previous" />
</asp:GridView>
这是我的数据绑定事件。
protected void GridViewYearWiseData_DataBound(object sender, EventArgs e)
{
var currentMethod = (new System.Diagnostics.StackFrame()).GetMethod().Name;
log.Info(AppConstants.StrStart + currentMethod);
try
{
GridRoundoffDecimal =Convert.ToInt32(resXResourceSet.GetString("GridMaxDecimals"));//Line of code to get from the database, the number of decimals to be displayed in the grid after the decimal point
System.Web.UI.WebControls.GridView grid = (System.Web.UI.WebControls.GridView)sender;
BoundField col1 = (BoundField)grid.Columns[1];
BoundField col2 = (BoundField)grid.Columns[2];
col1.DataFormatString = "{0:N" + GridRoundoffDecimal + "}";
col2.DataFormatString = "{0:N" + GridRoundoffDecimal + "}";
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), mLiquidateMain.GlobalConstants.script, mLiquidateMain.GlobalConstants.alertOf + GetErrorMessage(ex.Message) + "\");", true);
log.Error(ex.Message, ex);
}
finally
{
log.Info(AppConstants.StrEnd + currentMethod);
}
}
这是我的DataSource
关于我哪里出错的任何想法?