OK, I am getting this error
and here are the code sections. Line 192 is in this section
and then in the bind statement
And then the aspx page
Those are all just snippets, if it would be more helpful to post larger sections let me know, but I think I am likely just missing something simple. What I am doing is simply displaying a recordset in a gridview with conditional formatting like you would do in an Excel spreadhseet for management. It actually worked fine until I changed a number of the fields from asp:Boundfield to asp:TemplateField and now it writes out the first row and then fails with the above error. And I am sure that I am missing something trivial since it was working fine when I was using Boundfields...
Thanks!
Willie
Code:
Error in execution System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info) at System.Convert.ToInt16(String value) at CreditReports._viewCustomers.gvCredit_RowDataBound(Object sender, GridViewRowEventArgs e) in e:\kt-webs\JBK\CORPORATE\creditreports\ViewCustomersReports.aspx.cs:line 192 at System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e) at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at System.Web.UI.WebControls.BaseDataBoundControl.DataBind() at System.Web.UI.WebControls.GridView.DataBind() at CreditReports._viewCustomers.BindGridView() in e:\kt-webs\JBK\CORPORATE\creditreports\ViewCustomersReports.aspx.cs:line 121
and here are the code sections. Line 192 is in this section
Code:
protected void gvCredit_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
DropDownList ddlCompany;
ddlCompany = (DropDownList)e.Row.FindControl("ddlCompany");
if (!(ViewState["FilterCompany"] == null))
{
ddlCompany.SelectedValue = (string)ViewState["FilterCompany"];
}
else
{
ddlCompany.SelectedIndex = 0;
}
DropDownList ddlSyspro;
ddlSyspro = (DropDownList)e.Row.FindControl("ddlSyspro");
if (!(ViewState["FilterSyspro"] == null))
{
ddlSyspro.SelectedValue = (string)ViewState["FilterSyspro"];
}
else
{
ddlSyspro.SelectedIndex = 0;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Paydex
int? pdx = Convert.ToInt16(e.Row.Cells[9].Text); (LINE 192)
if (pdx == 0)
{
e.Row.Cells[9].BackColor = System.Drawing.Color.FromName("#FFFFFF"); // This will make row back color white
}
else if (pdx < 55)
{
e.Row.Cells[9].BackColor = System.Drawing.Color.FromName("#DC143C"); // This will make row back color red
}
else if (pdx < 70)
{
e.Row.Cells[9].BackColor = System.Drawing.Color.FromName("#FFFF99"); // This will make row back color yellow
}
else if (pdx >= 70)
{
e.Row.Cells[9].BackColor = System.Drawing.Color.FromName("#CCFFCC"); // This will make row back color mintgreen; blue is 99CCFF, c6efce
}
etc....
and then in the bind statement
Code:
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@FilterCompany", Company);
cmd.Parameters.AddWithValue("@FilterSyspro", ViewState["FilterSyspro"]);
cmd.Parameters.AddWithValue("@Year", Year);
cmd.Parameters.AddWithValue("@Month", Month);
cmd.Parameters.AddWithValue("@Analyzed", Analyzed);
cmd.Connection = con;
sda.SelectCommand = cmd;
DataSet dsCredit = new DataSet();
sda.Fill(dsCredit, "Credit");
DataView dvCredit = dsCredit.Tables["Credit"].DefaultView;
dvCredit.Sort = ViewState["SortExpression"].ToString();
gvCredit.DataSource = dvCredit;
gvCredit.DataBind(); LINE 121
DropDownList ddlCompany = (DropDownList)gvCredit.HeaderRow.FindControl("ddlCompany");
this.BindCompanyList(ddlCompany);
DropDownList ddlSyspro = (DropDownList)gvCredit.HeaderRow.FindControl("ddlSyspro");
this.BindSysproList(ddlSyspro);
And then the aspx page
Code:
<asp:BoundField DataField="DBNumber" HeaderText="D&B Number" ReadOnly="True" SortExpression="DBNumber" HeaderStyle-Wrap="false" ItemStyle-Wrap="false" />
<asp:BoundField DataField="NextReviewDue" HeaderText="Next Review Due" DataFormatString="{0:M/dd/yyyy}" ReadOnly="True" SortExpression="NextReviewDue" HeaderStyle-Wrap="true" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="DateReportPulled" HeaderText="Date Report Pulled" DataFormatString="{0:M/dd/yyyy}" ReadOnly="True" SortExpression="DateReportPulled" HeaderStyle-Wrap="true" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Date Analyzed" SortExpression="DateAnalyzed" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate >
<asp:Label ID="lblDateAnalyzed" runat="server" Text='<%# Bind("DateAnalyzed", "{0:d}") %>' />
</ItemTemplate>
<EditItemTemplate >
<asp:Checkbox ID="DateAnalyzed" runat="server" Text='<%# Bind("DateAnalyzed", "{0:d}")%>' AutoPostBack="true" OnCheckedChanged="chkSelect_CheckedChanged" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Paydex" SortExpression="Paydex" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblPaydex" runat="server" Text='<%# Bind("Paydex") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Paydex" runat="server" Text='<%# Bind("Paydex") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="3 Month Paydex" SortExpression="3MonthPaydex" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lbl3MonthPaydex" runat="server" Text='<%# Bind("3MonthPaydex") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="MonthPaydex" runat="server" Text='<%# Bind("3MonthPaydex") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Commercial Credit Class" SortExpression="CommercialCreditClass" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblCommercialCreditClass" runat="server" Text='<%# Bind("CommercialCreditClass") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="CommercialCreditClass" runat="server" Text='<%# Bind("CommercialCreditClass") %>' />
</EditItemTemplate>
</asp:TemplateField>
Those are all just snippets, if it would be more helpful to post larger sections let me know, but I think I am likely just missing something simple. What I am doing is simply displaying a recordset in a gridview with conditional formatting like you would do in an Excel spreadhseet for management. It actually worked fine until I changed a number of the fields from asp:Boundfield to asp:TemplateField and now it writes out the first row and then fails with the above error. And I am sure that I am missing something trivial since it was working fine when I was using Boundfields...
Thanks!
Willie