Click here to Skip to main content
15,900,973 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: asp.net Pin
vvashishta4-Jun-12 22:13
vvashishta4-Jun-12 22:13 
Generalasp.net and c# Pin
sathik174-Jun-12 0:34
sathik174-Jun-12 0:34 
AnswerRe: asp.net and c# Pin
Rahul Rajat Singh4-Jun-12 1:04
professionalRahul Rajat Singh4-Jun-12 1:04 
GeneralRe: asp.net and c# Pin
Pankaj Nikam4-Jun-12 19:27
professionalPankaj Nikam4-Jun-12 19:27 
QuestionDisplay Excel File in .aspx Page Pin
paas1-Jun-12 4:53
paas1-Jun-12 4:53 
AnswerRe: Display Excel File in .aspx Page Pin
Ravi Sant3-Jun-12 18:29
Ravi Sant3-Jun-12 18:29 
QuestionShow MS Lync presence in aspx web page Pin
meetprabhum1-Jun-12 3:32
meetprabhum1-Jun-12 3:32 
QuestionASP.Net Logout issue Pin
berba1-Jun-12 2:47
berba1-Jun-12 2:47 
AnswerRe: ASP.Net Logout issue Pin
keyur satyadev2-Jun-12 1:10
keyur satyadev2-Jun-12 1:10 
AnswerRe: ASP.Net Logout issue Pin
taha bahraminezhad Jooneghani3-Jun-12 2:19
taha bahraminezhad Jooneghani3-Jun-12 2:19 
AnswerRe: ASP.Net Logout issue Pin
thatraja4-Jun-12 17:13
professionalthatraja4-Jun-12 17:13 
AnswerRe: ASP.Net Logout issue Pin
august_star4-Jun-12 21:28
august_star4-Jun-12 21:28 
Question2010 web form problem Pin
sc steinhayse31-May-12 11:22
sc steinhayse31-May-12 11:22 
AnswerRe: 2010 web form problem Pin
R. Giskard Reventlov31-May-12 15:20
R. Giskard Reventlov31-May-12 15:20 
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 

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.