返回首页

我要插入到Datbase一些数据,我采取四场两个DropDownList和两个文本框,
当我保存在数据库中的数据后,提交"按钮,这个genrate一个错误消息。这是

'proDropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

和我的DropDownList的代码 - {C}
你可以帮助我吗?

回答

评论会员:游客 时间:2012/02/04
hitech_ssc:数据绑定到DropDownList的UR资料存取dropdownlist.selectedvale第一次看到你的DropDownList是否有项目或不前。
亮点功能
] - 一个老但有用的链接,如果您使用的是报告模式的ListView

搜索功能
在互联网上做一个搜索会给你这个结果万吨。

但是,您可以开始使用{A}
使用参考
评论会员:ABHI9278 时间:2012/02/04
.................方案保存数据库使用的DropDownList的数据.........

使用系统;
使用System.Configuration;
使用System.Data;
使用System.Data.SqlClient的
使用System.Linq的;
使用的System.Web;
使用System.Web.Security;
CSDN社区 -
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml.Linq的;

公共部分类_Default:System.Web.UI.Page的
{
保护无效的Page_Load(对象发件人,EventArgs的五)
{

 0; }
保护无效TextBox1_TextChanged(对象发件人,EventArgs的五)
{

& #160; }
保护无效中button1_Click(对象发件人,EventArgs的五)
{
SqlConnection的CON =新的SqlConnection(@"数据源= INFOSYS-E28D9BC \ SQLEXPRESS的初始目录=阿比纳夫;集成安全性= TRUE")
con.Open()
SqlCommand的CMD =新的SqlCommand("save_record",CON)
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ ENAME",TextBox1.Text);
cmd.Parameters.Add("@ fname"先,TextBox2.Text)
cmd.Parameters.Add(的"_AT_国",DropDownList1.SelectedItem.Text);
cmd.Parameters.Add(的"_AT_城市",DropDownList2.SelectedItem.Text);
cmd.Parameters.Add("@暴民"Convert.ToInt32(TextBox3.Text)的)
我= cmd.ExecuteNonQuery()
如果(我== 1)
 60; Label1.Text ="记录被插入成功";
 60; 其他
&# 160;Label1.Text ="请再试一次";
 60;con.Close()
}
保护无效DropDownList1_SelectedIndexChanged(对象发件人,EventArgs的五)
 60; {

}
  ;保护无效TextBox2_TextChanged(对象发件人,EventArgs的五)
{

}
保护无效DropDownList2_SelectedIndexChanged(对象发件人,EventArgs的五)
{

}
&# 160; 保护无效Button2_Click(对象发件人,EventArgs的五)
{
TextBox1.Text ="";
TextBox2.Text ="";
&# 160; TextBox3.Text ="";
&# 160;
}
}

..............设计规范...................
粘贴在Visual Studio 2008 IDE中源......
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

 

                                                                             

        ...........USER INFORMATION FORM...........<br />

        <br />

        Enter Name  

        <asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>

        Father Name

        <asp:TextBox ID="TextBox2" runat="server" ontextchanged="TextBox2_TextChanged"></asp:TextBox>

        <br />

        <br />

        Country        

        <asp:DropDownList ID="DropDownList1" runat="server"

            onselectedindexchanged="DropDownList1_SelectedIndexChanged">

            <asp:ListItem>INDIA</asp:ListItem>

            <asp:ListItem>PAKISTAN</asp:ListItem>

        </asp:DropDownList>

                   

        City   

        <asp:DropDownList ID="DropDownList2" runat="server"

            onselectedindexchanged="DropDownList2_SelectedIndexChanged"

            style="height: 22px">

            <asp:ListItem>KASHIPUR</asp:ListItem>

            <asp:ListItem>LAHOR</asp:ListItem>

        </asp:DropDownList>

        <br />

        <br />

        <br />

        Mob No.            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

      

        <br />

        <br />

        <br />

        <br />

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />

           

        <asp:Button ID="Button2" runat="server" Text="Cancel" onclick="Button2_Click" />

        <br />

        <br />

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

 

    </div>

    </form>

</body>

</html>