誰かが私を助けてくれませんか?このエラーは正しい形式ではないことを示していますが、整数としてリストされています。私が何を馬鹿にしているか教えてくれたら、あなたは本当に私のヒーローになる. 私は誰かの助けに感謝しています。はい、私はasp.netを始めたばかりなので、許してください。
このページは、顧客 ID からインシデントを取得する調査です。それはsqlconnectionを使用しており、送信ボタンを押してからエラーになるまで問題ありません。
これは私が取得し続けるエラーコードであり、私はそれを見ていないと思います. 選択した値に問題があると考えているこのエラーが発生する理由がわかりません。その価値のために、これが問題であることを望んでいる直前に if ステートメントを追加しましたが、明らかにそうではありませんでした。
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.
FormatException: Input string was not in a correct format.
Source Error:
Line 56: s.CustomerID = Convert.ToInt32(txtCustomerID.Text);
Line 57: if (lstIncident.SelectedIndex > -1)
Line 58: s.IncidentID = Convert.ToInt32(lstIncident.SelectedValue);
Line 59: if (rblResponse.SelectedIndex != -1)
Line 60: {
ページの背後にあるコード
public partial class CustomerSurvey : System.Web.UI.Page
{
private DataView IncidentsTable;
protected void Page_Load(object sender, EventArgs e)
{
txtCustomerID.Focus();
}
protected void btnGetIncidents_Click(object sender, EventArgs e)
{
IncidentsTable = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
IncidentsTable.RowFilter = "CustomerID = " + Convert.ToInt32(txtCustomerID.Text) + " AND DateClosed is Not Null";
if (IncidentsTable.Count > 0)
{
this.DisplayIncidents();
this.Enable(true);
lstIncident.Focus();
}
else
{
lblIncidentCount.Text = "I'm sorry there are no incidents that can be surveyed at this time.";
this.Enable(false);
}
}
private void DisplayIncidents()
{
lstIncident.Items.Add(new ListItem("--Select an Incident--"));
for (int j = 0; j < IncidentsTable.Count; j++)
{
DataRowView row = IncidentsTable[j];
Incident i = new Incident();
i.IncidentID = Convert.ToInt32(row["IncidentID"]);
i.ProductCode = row["ProductCode"].ToString();
i.DateClosed = Convert.ToDateTime(row["DateClosed"]);
i.Title = row["Title"].ToString();
lstIncident.Items.Add(i.CustomerIncidentDisplay());
}
lstIncident.SelectedIndex = 0;
lblIncidentCount.Text = "";
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Survey s = new Survey();
s.CustomerID = Convert.ToInt32(txtCustomerID.Text);
if (lstIncident.SelectedIndex > -1)
s.IncidentID = Convert.ToInt32(lstIncident.SelectedValue);
if (rblResponse.SelectedIndex != -1)
{
s.ResponseTime = Convert.ToInt32(rblResponse.SelectedValue);
}
if (rblTechEfficiency.SelectedIndex != -1)
{
s.TechEfficiency = Convert.ToInt32(rblTechEfficiency.SelectedValue);
}
if (rblProblemResolution.SelectedIndex != -1)
{
s.Resolution = Convert.ToInt32(rblProblemResolution.SelectedValue);
}
s.Comments = txtComments.Text;
if (ckbContactMe.Checked)
{
s.Contact = true;
if (rdoContactEmail.Checked)
{
s.ContactBy = "Email";
}
else
{
s.ContactBy = "Phone";
}
Session.Add("Contact", true);
}
else
{
s.Contact = false;
Session.Add("Contact", false);
}
Response.Redirect("SurveyComplete.aspx");
}
}
private void Enable(bool e)
{
lstIncident.Enabled = e;
lblIncidents.Enabled = e;
lblResponse.Enabled = e;
lblProblemResolution.Enabled = e;
lblTechEfficiency.Enabled = e;
lblComments.Enabled = e;
rdoContactEmail.Enabled = e;
rdoContactPhone.Enabled = e;
rblProblemResolution.Enabled = e;
rblResponse.Enabled = e;
rblTechEfficiency.Enabled = e;
lblContact.Enabled = e;
txtComments.Enabled = e;
ckbContactMe.Enabled = e;
btnSubmit.Enabled = e;
}
}
これが Incident という私のクラスです
public class Incident
{
public int IncidentID { get; set; }
public int CustomerID { get; set; }
public string ProductCode { get; set; }
public int TechID { get; set; }
public string DateOpened { get; set; }
public DateTime DateClosed { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string CustomerIncidentDisplay()
{
return "Incident for product " + ProductCode + " closed " + DateClosed.ToShortDateString() +
" (" + Title + ")";
}
}
public Incident()
{
}
これはマスターページからのものですが、ここにページがあります
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<label>Enter your customer ID:</label>
<asp:TextBox ID="txtCustomerID" runat="server" Width="183px"></asp:TextBox>
<asp:Button ID="btnGetIncidents" runat="server" Text="Get Incidents" OnClick="btnGetIncidents_Click" ValidationGroup="CustomerID" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCustomerID" ErrorMessage="You must enter a customer ID" ForeColor="Red" ValidationGroup="CustomerID" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtCustomerID" ErrorMessage="Customer ID must be a positive whole number" ForeColor="Red" Operator="DataTypeCheck" Type="Integer" ValidationGroup="CustomerID" Display="Dynamic"></asp:CompareValidator>
<br />
<asp:Label ID="lblIncidentCount" runat="server" ForeColor="Red"></asp:Label>
<br />
<asp:ListBox ID="lstIncident" runat="server" Width="622px" Enabled="False" AutoPostBack="True"></asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TechSupportConnectionString %>" SelectCommand="SELECT [IncidentID], [CustomerID], [ProductCode], [TechID], [DateOpened], [DateClosed], [Title] FROM [Incidents] ORDER BY [DateClosed]"></asp:SqlDataSource>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="lstIncident" ErrorMessage="You must select an incident" ForeColor="Red" ValidationGroup="Incidents" Display="Dynamic" ></asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblIncidents" runat="server" Text="Please rate this incident by the following categories: " Enabled="False"></asp:Label><br />
<table id="tblIncidents">
<tr>
<td> <asp:Label ID="lblResponse" runat="server" Text="Response Time:" Enabled="False"></asp:Label></td>
<td><asp:RadioButtonList ID="rblResponse" runat="server" Font-Names="Arial" Font-Size="Small" RepeatDirection="Horizontal" Enabled="False">
<asp:ListItem Value="1">Not Satisfied</asp:ListItem>
<asp:ListItem Value="2">Somewhat Satisfied</asp:ListItem>
<asp:ListItem Value="3">Satisfied</asp:ListItem>
<asp:ListItem Value="4">Completely Satisfied</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td><asp:Label ID="lblTechEfficiency" runat="server" Text="Technician Efficiency:" Enabled="False"></asp:Label></td>
<td><asp:RadioButtonList ID="rblTechEfficiency" runat="server" RepeatDirection="Horizontal" Font-Names="Arial" Font-Size="Small" Enabled="False">
<asp:ListItem Value="1">Not Satisfied</asp:ListItem>
<asp:ListItem Value="2">Somewhat Satisfied</asp:ListItem>
<asp:ListItem Value="3">Satisfied</asp:ListItem>
<asp:ListItem Value="4">Completely Satisfied</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td><asp:Label ID="lblProblemResolution" runat="server" Text="Problem Resolution:" Enabled="False"></asp:Label></td>
<td><asp:RadioButtonList ID="rblProblemResolution" runat="server" RepeatDirection="Horizontal" Font-Names="Arial" Font-Size="Small" Enabled="False">
<asp:ListItem Value="1">Not Satisfied</asp:ListItem>
<asp:ListItem Value="2">Somewhat Satisfied</asp:ListItem>
<asp:ListItem Value="3">Satisfied</asp:ListItem>
<asp:ListItem Value="4">Completely Satisfied</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
</table>
<asp:Label ID="lblComments" runat="server" Text="Additional Comments:" Enabled="False"></asp:Label>
<asp:TextBox ID="txtComments" runat="server" Height="81px" Width="551px" Enabled="False" Rows="4" TextMode="MultiLine"></asp:TextBox>
<br />
<br />
<asp:CheckBox ID="ckbContactMe" runat="server" Enabled="False" />
<asp:Label ID="lblContact" runat="server" Text="Please contact me to discuss this incident" Enabled="False"></asp:Label>
<br />
<asp:RadioButton ID="rdoContactEmail" runat="server" GroupName="ContactBy" Enabled="False" Text="Contact By Email" /><br />
<asp:RadioButton ID="rdoContactPhone" runat="server" Enabled="False" GroupName="ContactBy" Text="Contact By Phone" />
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" Enabled="False" ValidationGroup="Incidents" Width="123px" />
</asp:Content>