Im using dropdownlist in Gridview,manualy i'm adding list element to dropdown list,
the code is as in below. when i compile i'm getting error like this....
" 'drdpStatusType' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value"
please send how to fix this
thanks in advance...........
DataTextField="StatusType" DataValueField="StatusType" SelectedValue='<%# Bind("StatusType") %>' AppendDataBoundItems="True">
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jun 6, 2012, 10:38 AM
Try this...
Create table Employees(StatusType varchar(50))
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Dropdownlist_inside_gridview._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
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;
using System.Data.SqlClient;
namespace Dropdownlist_inside_gridview
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter sqlda = new SqlDataAdapter();
SqlCommand com = new SqlCommand();
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
private void bindgrid()
{
SqlConnection conn = new SqlConnection(connStr);
dt = new DataTable();
com.Connection = conn;
com.CommandText = "SELECT * FROM Employees";
sqlda = new SqlDataAdapter(com);
sqlda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control ctrl = e.Row.FindControl("ddlTest");
if (ctrl != null)
{
DropDownList dd = ctrl as DropDownList;
SqlConnection conn = new SqlConnection(connStr);
dt = new DataTable();
com.Connection = conn;
com.CommandText = "SELECT * FROM Employees";
sqlda = new SqlDataAdapter(com);
sqlda.Fill(dt);
dd.DataTextField = "StatusType";
dd.DataValueField = "StatusType";
dd.DataSource = dt;
dd.DataBind();
}
}
}
}
}
Thanks