我有一個下拉列表。我添加了一個默認值到一個下拉列表框,這個代碼在下拉列表中使用confirmbuttonextender時重複值
<asp:DropDownList ID="DDLCase" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDLCase_SelectedIndexChanged" AppendDataBoundItems="true" >
<asp:ListItem Value="">Select Member Report ID</asp:ListItem>
</asp:DropDownList>
,比如我有DB值,如123,1234
當我運行我的表單,點擊123和1234什麼都沒有發生。然而,當我去點擊列表項值,他們給了我一些錯誤
Conversion failed when converting the varchar value 'Select Member Report ID' to data type int.
這是我對我在我的頁面加載DDL後端代碼。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");
SqlCommand cm = new SqlCommand("Select pr.policereportid from PoliceReport pr, AdminOfficialReport aor, MemberReport mr where pr.memberreportid=mr.memberreportid and mr.caseprogress='settled' and aor.officialreport IS NULL", con);
con.Open();
SqlDataReader dr;
dr = cm.ExecuteReader();
while (dr.Read())
{
DDLCase.Items.Add(dr["policereportid"].ToString());
}
DDLCase.Items.Insert(0, new ListItem("Select Member Report ID", "-1"));
dr.Close();
con.Close();
}
}
這是我的錯誤發生的地方。它發生在dr = cm.ExecuteReader();周圍的區域。
protected void DDLCase_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");
con.Open();
SqlCommand cm = new SqlCommand("Select lro.fullname, lro.contact, mr.typeofcrime, mr.location,mr.crdatetime, pr.policeid, pr.prdatetime, pr.policereport, pr.image1, mr.citizenreport from MemberReport mr, PoliceReport pr, LoginRegisterOthers lro where pr.policereportid = '" + DDLCase.SelectedItem.Text + "' and mr.memberreportid=pr.memberreportid and lro.username=mr.username and mr.caseprogress='settled'", con);
SqlDataReader dr;
dr = cm.ExecuteReader();
if (dr.Read())
{
lblFullName.Text = dr["fullname"].ToString();
lblContact.Text = dr["contact"].ToString();
lblTOC.Text = dr["typeofcrime"].ToString();
lblLocation.Text = dr["location"].ToString();
lblCRDT.Text = dr["crdatetime"].ToString();
lblPicture.Text = dr["image1"].ToString();
lblAssign.Text = dr["policeid"].ToString();
lblPRDT.Text = dr["prdatetime"].ToString();
lblCR.Text = dr["citizenreport"].ToString();
lblPR.Text = dr["policereport"].ToString();
}
con.Close();
}
我該如何解決這個問題?
請您的具體問題http://meta.stackexchange.com/questions/10647/how-do-i-write-a-good-title –
我@SonerGönül同意更新您的標題。這與標題無關。 – jAC
只是設置'價值=「 - 1」',它會工作 – Rahul