Click here to Skip to main content
15,884,388 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: 2010 web form problem Pin
taha bahraminezhad Jooneghani3-Jun-12 2:48
taha bahraminezhad Jooneghani3-Jun-12 2:48 
Questioncalling a function from a hyperlink Pin
wiins31-May-12 8:08
wiins31-May-12 8:08 
AnswerRe: calling a function from a hyperlink Pin
jkirkerx31-May-12 13:30
professionaljkirkerx31-May-12 13:30 
GeneralRe: calling a function from a hyperlink Pin
wiins31-May-12 22:15
wiins31-May-12 22:15 
GeneralRe: calling a function from a hyperlink Pin
jkirkerx1-Jun-12 6:57
professionaljkirkerx1-Jun-12 6:57 
GeneralRe: calling a function from a hyperlink Pin
wiins8-Jun-12 4:46
wiins8-Jun-12 4:46 
GeneralRe: calling a function from a hyperlink Pin
jkirkerx8-Jun-12 10:53
professionaljkirkerx8-Jun-12 10:53 
Question'cmbGender' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Pin
mudunurusv30-May-12 23:36
mudunurusv30-May-12 23:36 
I am getting the following error while editing values in a GridView row.I am posting my code and error below.

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


ASP.NET
     <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomerData.aspx.cs" Inherits="CustomerData" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!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>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Code,Type" ShowFooter="True" 
                OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand" 
                OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                    <Columns>
                        <asp:TemplateField HeaderText="Name" SortExpression="Name">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtNewName" runat="server"></asp:TextBox>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Gender" SortExpression="Gender">
                            <EditItemTemplate>
                                <asp:DropDownList ID="cmbGender" runat="server" SelectedValue='<%# Eval("Gender") %>'>
                                    <asp:ListItem Value="Male" Text="Male"></asp:ListItem>
                                    <asp:ListItem Value="Female" Text="Female"></asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList ID="cmbNewGender" runat="server">
                                    <asp:ListItem Value="Male" Text="Male"></asp:ListItem>
                                    <asp:ListItem Value="Female" Text="Female"></asp:ListItem>
                                </asp:DropDownList>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Gender") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="City" SortExpression="City">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtNewCity" runat="server"></asp:TextBox>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Bind("City") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="State" SortExpression="State">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("State") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtNewState" runat="server"></asp:TextBox>
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%# Bind("State") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Type" SortExpression="Type">
                            <EditItemTemplate>
                                <asp:DropDownList ID="cmbType" runat="server" DataTextField="Type" DataValueField="Type">
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label5" runat="server" Text='<%# Eval("Type") %>'></asp:Label>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:DropDownList ID="cmbNewType" runat="server" DataTextField="Type" DataValueField="Type">
                                </asp:DropDownList>
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <EditItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                    Text="Update"></asp:LinkButton>
                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                    Text="Cancel"></asp:LinkButton>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                    Text="Edit"></asp:LinkButton>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:LinkButton ID="LinkButton3" runat="server">AddNew</asp:LinkButton>
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowDeleteButton="True" />
                    </Columns>
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
      </div>
    </form>
</body>
</html>


C#
    using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CustomerData : System.Web.UI.Page
{
    CustomersCls customer = new CustomersCls();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillCustomerInGrid();
        }
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
       
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList cmbType = (DropDownList)e.Row.FindControl("cmbType");

            if (cmbType != null)
            {
                cmbType.DataSource = customer.FetchCustomerType();
                cmbType.DataBind();
                cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();

            }

        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DropDownList cmbNewType = (DropDownList)e.Row.FindControl("cmbNewType");
            cmbNewType.DataSource = customer.FetchCustomerType();
            cmbNewType.DataBind();
        }
       
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        FillCustomerInGrid();

    }
    
    private void FillCustomerInGrid()
    {
        
        DataTable dt = customer.Fetch();


        if (dt.Rows.Count > 0)
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GridView1.DataSource = dt;
            GridView1.DataBind();

            int TotalColumns = GridView1.Rows[0].Cells.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GridView1.Rows[0].Cells[0].Text = "No Record found";
        }
    }
}


Please help me to solve this error.Thanks in advance
AnswerRe: 'cmbGender' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Pin
Sandeep Mewara31-May-12 0:43
mveSandeep Mewara31-May-12 0:43 
QuestionGridview in Repeater Pin
zeeShan anSari30-May-12 4:33
zeeShan anSari30-May-12 4:33 
AnswerRe: Gridview in Repeater Pin
Sandeep Mewara30-May-12 10:17
mveSandeep Mewara30-May-12 10:17 
GeneralRe: Gridview in Repeater Pin
Apocalypse Now31-May-12 15:17
Apocalypse Now31-May-12 15:17 
GeneralRe: Gridview in Repeater Pin
Sandeep Mewara31-May-12 16:42
mveSandeep Mewara31-May-12 16:42 
GeneralRe: Gridview in Repeater Pin
Apocalypse Now1-Jun-12 15:19
Apocalypse Now1-Jun-12 15:19 
AnswerRe: Gridview in Repeater Pin
wikizhao31-May-12 22:26
wikizhao31-May-12 22:26 
AnswerRe: Gridview in Repeater Pin
taha bahraminezhad Jooneghani3-Jun-12 2:09
taha bahraminezhad Jooneghani3-Jun-12 2:09 
QuestionFind index or row in gridview with RadioButton Pin
Franco Cipriano30-May-12 4:03
Franco Cipriano30-May-12 4:03 
AnswerRe: Find index or row in gridview with RadioButton Pin
Sandeep Mewara30-May-12 10:11
mveSandeep Mewara30-May-12 10:11 
GeneralRe: Find index or row in gridview with RadioButton Pin
Franco Cipriano30-May-12 10:35
Franco Cipriano30-May-12 10:35 
GeneralRe: Find index or row in gridview with RadioButton Pin
Sandeep Mewara30-May-12 10:41
mveSandeep Mewara30-May-12 10:41 
GeneralRe: Find index or row in gridview with RadioButton Pin
Franco Cipriano31-May-12 4:44
Franco Cipriano31-May-12 4:44 
GeneralRe: Find index or row in gridview with RadioButton Pin
Sandeep Mewara31-May-12 5:06
mveSandeep Mewara31-May-12 5:06 
Questionget the file path in web project when running unit test project Pin
siva45530-May-12 0:34
siva45530-May-12 0:34 
AnswerRe: get the file path in web project when running unit test project Pin
Sandeep Mewara30-May-12 2:26
mveSandeep Mewara30-May-12 2:26 
QuestionRestrict object's properties to be added in ASP.NET application state Pin
Tesic Goran29-May-12 20:20
professionalTesic Goran29-May-12 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.