Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Want to Insert Some data into Datbase, i take four field two dropdownlist and two textbox,
when i save data in database, after submit the button , this genrate an error message. that is
SQL
'proDropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

and my dropdownlist code is -
ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="161px">

Can you Help Me Please?
Posted
Updated 29-Aug-11 20:17pm
v2
Comments
hitech_s 30-Aug-11 2:20am    
how u r binding data to dropdownlist?
check data exist or not in dropdownlist
if dropdown doesnot contain data then such type of error will raise
thats it

bind data to dropdownlist before u r accessing dropdownlist.selectedvale.
first see whether u r dropdownlist has items or not.
 
Share this answer
 
v3
Highlight functionality
http://support.microsoft.com/kb/181440[^] - an old link but useful if you are using the ListView in report mode.

Search functionality
Doing a search on the internet will give you tons of results for this.

However, you can start with http://msdn.microsoft.com/en-us/library/ms171644.aspx[^] or A User-Searchable TextBox, RichTextBox, ListView, and TreeView in C#[^].
 
Share this answer
 
 
Share this answer
 
.................PROGRAM FOR SAVING DATA IN DATABASE USING DROPDOWNLIST..........






using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=INFOSYS-E28D9BC\SQLEXPRESS;Initial Catalog=abhinav;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("save_record", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ename",TextBox1.Text);
cmd.Parameters.Add("@fname", TextBox2.Text);
cmd.Parameters.Add("@country",DropDownList1.SelectedItem.Text);
cmd.Parameters.Add("@city",DropDownList2.SelectedItem.Text);
cmd.Parameters.Add("@mob", Convert.ToInt32(TextBox3.Text));
int i = cmd.ExecuteNonQuery();
if (i == 1)
Label1.Text = "Record is inserted successfully";
else
Label1.Text = "Please Try Again";
con.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{

}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text= "";
TextBox3.Text= "";

}
}



..............DESIGN CODE................
PASTE IT IN YOUR VISUAL STUDIO 2008 IDE SOURCE.......






XML
<%@ 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>

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        ...........USER INFORMATION FORM...........<br />
        <br />
        Enter Name&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Father Name
        <asp:TextBox ID="TextBox2" runat="server" ontextchanged="TextBox2_TextChanged"></asp:TextBox>
        <br />
        <br />
        Country&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem>INDIA</asp:ListItem>
            <asp:ListItem>PAKISTAN</asp:ListItem>
        </asp:DropDownList>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        City&nbsp;&nbsp;&nbsp;
        <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.&nbsp;&nbsp;&nbsp;&nbsp;        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br />
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900