473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

what's wrong?i need your help.

I want use dropdownlist contral in gridview
but have trouble now
mycode here:
i'm very sorry for my poor english

<%@ 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>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSourceclass"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True" SortExpression="id" />
<asp:TemplateField HeaderText="specialityid"
SortExpression="specialityid">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField HeaderText="masterid"
SortExpression="masterid">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSourceteacher"
DataTextField="realname" DataValueField="id"
SelectedValue='<%# Eval("masterid") %>'>
</asp:DropDownList><asp:SqlDataSource
ID="SqlDataSourceteacher" runat="server" ConnectionString="<%$
ConnectionStrings:studentConnectionString %>"
SelectCommand="SELECT [id], [realname] FROM
[teacher]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Bind("masterid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("masterid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="roomnum" HeaderText="roomnum"
SortExpression="roomnum" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSourceclass" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [class] WHERE [id] = @id"
InsertCommand="INSERT INTO [class] ([id], [specialityid], [name],
[masterid], [roomnum]) VALUES (@id, @specialityid, @name, @masterid,
@roomnum)"
SelectCommand="SELECT [id], [specialityid], [name], [masterid],
[roomnum] FROM [class]"
UpdateCommand="UPDATE [class] SET [specialityid] =
@specialityid, [name] = @name, [masterid] = @masterid, [roomnum] = @roomnum
WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
<asp:Parameter Name="id" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

error blew

Server Error in '/WebSite1' Application.
--------------------------------------------------------------------------------

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has a
SelectedValue which is invalid because it does not exist in the list of
items.
Parameter name: value

Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is
invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +976
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelec t() +32
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.DetailsView.CreateChildC ontrols(IEnumerable
dataSource, Boolean dataBinding) +3174
System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +90
System.Web.UI.WebControls.DetailsView.PerformDataB inding(IEnumerable
data) +31
System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +126
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments,
DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.Perform Select() +154
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.WebControls.DetailsView.DataBind() +24
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +91
System.Web.UI.WebControls.DetailsView.EnsureDataBo und() +198
System.Web.UI.WebControls.BaseDataBoundControl.OnP reRender(EventArgs e)
+33
System.Web.UI.WebControls.DetailsView.OnPreRender( EventArgs e) +62
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint
Dec 14 '05 #1
7 1906
It simply sounds like the Eval("MasterId") is returning a value not in the
dropdownlist. Is that possible? Could some of your records possibly have a
null value or some other default or unknown value?

You should try to figure out which MasterId is screwing it up. Also, you
might wanna hook some of this in codebehid, it would be easier to debug.

Karl

--

MY ASP.Net tutorials
http://www.openmymind.net/

"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:uV**************@TK2MSFTNGP14.phx.gbl...
I want use dropdownlist contral in gridview
but have trouble now
mycode here:
i'm very sorry for my poor english

<%@ 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>
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSourceclass"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True" SortExpression="id" />
<asp:TemplateField HeaderText="specialityid"
SortExpression="specialityid">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField HeaderText="masterid"
SortExpression="masterid">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSourceteacher"
DataTextField="realname" DataValueField="id"
SelectedValue='<%# Eval("masterid") %>'>
</asp:DropDownList><asp:SqlDataSource
ID="SqlDataSourceteacher" runat="server" ConnectionString="<%$
ConnectionStrings:studentConnectionString %>"
SelectCommand="SELECT [id], [realname] FROM
[teacher]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Bind("masterid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("masterid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="roomnum" HeaderText="roomnum"
SortExpression="roomnum" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSourceclass" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [class] WHERE [id] = @id"
InsertCommand="INSERT INTO [class] ([id], [specialityid], [name],
[masterid], [roomnum]) VALUES (@id, @specialityid, @name, @masterid,
@roomnum)"
SelectCommand="SELECT [id], [specialityid], [name], [masterid],
[roomnum] FROM [class]"
UpdateCommand="UPDATE [class] SET [specialityid] =
@specialityid, [name] = @name, [masterid] = @masterid, [roomnum] =
@roomnum WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
<asp:Parameter Name="id" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

error blew

Server Error in '/WebSite1' Application.
--------------------------------------------------------------------------------

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has
a SelectedValue which is invalid because it does not exist in the list of
items.
Parameter name: value

Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is
invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +976
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelec t() +32
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.DetailsView.CreateChildC ontrols(IEnumerable
dataSource, Boolean dataBinding) +3174

System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +90
System.Web.UI.WebControls.DetailsView.PerformDataB inding(IEnumerable
data) +31

System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +126
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments,
DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.Perform Select() +154
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.WebControls.DetailsView.DataBind() +24
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +91
System.Web.UI.WebControls.DetailsView.EnsureDataBo und() +198
System.Web.UI.WebControls.BaseDataBoundControl.OnP reRender(EventArgs e)
+33
System.Web.UI.WebControls.DetailsView.OnPreRender( EventArgs e) +62
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint

Dec 14 '05 #2
thank u,karl
your analyse is very exactly.
but the question is that how can i deel with the unknow value or null value?

thanks again.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> дÈëÏûÏ¢ÐÂÎÅ:%2****************@TK2MSFTNGP11.phx.g bl...
It simply sounds like the Eval("MasterId") is returning a value not in the
dropdownlist. Is that possible? Could some of your records possibly have
a null value or some other default or unknown value?

You should try to figure out which MasterId is screwing it up. Also, you
might wanna hook some of this in codebehid, it would be easier to debug.

Karl

--

MY ASP.Net tutorials
http://www.openmymind.net/

"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:uV**************@TK2MSFTNGP14.phx.gbl...
I want use dropdownlist contral in gridview
but have trouble now
mycode here:
i'm very sorry for my poor english

<%@ 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>
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSourceclass"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True" SortExpression="id" />
<asp:TemplateField HeaderText="specialityid"
SortExpression="specialityid">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("specialityid") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("specialityid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField HeaderText="masterid"
SortExpression="masterid">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"
runat="server" DataSourceID="SqlDataSourceteacher"
DataTextField="realname" DataValueField="id"
SelectedValue='<%# Eval("masterid") %>'>
</asp:DropDownList><asp:SqlDataSource
ID="SqlDataSourceteacher" runat="server" ConnectionString="<%$
ConnectionStrings:studentConnectionString %>"
SelectCommand="SELECT [id], [realname] FROM
[teacher]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("masterid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("masterid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="roomnum" HeaderText="roomnum"
SortExpression="roomnum" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSourceclass" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [class] WHERE [id] = @id"
InsertCommand="INSERT INTO [class] ([id], [specialityid], [name],
[masterid], [roomnum]) VALUES (@id, @specialityid, @name, @masterid,
@roomnum)"
SelectCommand="SELECT [id], [specialityid], [name],
[masterid], [roomnum] FROM [class]"
UpdateCommand="UPDATE [class] SET [specialityid] =
@specialityid, [name] = @name, [masterid] = @masterid, [roomnum] =
@roomnum WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
<asp:Parameter Name="id" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

error blew

Server Error in '/WebSite1' Application.
--------------------------------------------------------------------------------

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1'
has a SelectedValue which is invalid because it does not exist in the
list of items.
Parameter name: value

Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which
is invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +976
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelec t() +32
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.DetailsView.CreateChildC ontrols(IEnumerable
dataSource, Boolean dataBinding) +3174

System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +90
System.Web.UI.WebControls.DetailsView.PerformDataB inding(IEnumerable
data) +31

System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +126
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments
arguments, DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.Perform Select() +154
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.WebControls.DetailsView.DataBind() +24
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +91
System.Web.UI.WebControls.DetailsView.EnsureDataBo und() +198
System.Web.UI.WebControls.BaseDataBoundControl.OnP reRender(EventArgs e)
+33
System.Web.UI.WebControls.DetailsView.OnPreRender( EventArgs e) +62
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint


Dec 15 '05 #3
You need to do conditional binding. Giving your scenario, I think your only
solution is to hook into the OnItemDataBound event. You can learn more at:
http://openmymind.net/index.aspx?documentId=8#4.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
thank u,karl
your analyse is very exactly.
but the question is that how can i deel with the unknow value or null
value?

thanks again.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:%2****************@TK2MSFTNGP11.phx.g bl...
It simply sounds like the Eval("MasterId") is returning a value not in
the dropdownlist. Is that possible? Could some of your records possibly
have a null value or some other default or unknown value?

You should try to figure out which MasterId is screwing it up. Also, you
might wanna hook some of this in codebehid, it would be easier to debug.

Karl

--

MY ASP.Net tutorials
http://www.openmymind.net/

"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:uV**************@TK2MSFTNGP14.phx.gbl...
I want use dropdownlist contral in gridview
but have trouble now
mycode here:
i'm very sorry for my poor english

<%@ 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>
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SqlDataSourceclass"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True" SortExpression="id" />
<asp:TemplateField HeaderText="specialityid"
SortExpression="specialityid">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("specialityid") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("specialityid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("specialityid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:TemplateField HeaderText="masterid"
SortExpression="masterid">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"
runat="server" DataSourceID="SqlDataSourceteacher"
DataTextField="realname" DataValueField="id"
SelectedValue='<%# Eval("masterid") %>'>
</asp:DropDownList><asp:SqlDataSource
ID="SqlDataSourceteacher" runat="server" ConnectionString="<%$
ConnectionStrings:studentConnectionString %>"
SelectCommand="SELECT [id], [realname] FROM
[teacher]"></asp:SqlDataSource>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("masterid") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("masterid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="roomnum" HeaderText="roomnum"
SortExpression="roomnum" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSourceclass" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [class] WHERE [id] = @id"
InsertCommand="INSERT INTO [class] ([id], [specialityid], [name],
[masterid], [roomnum]) VALUES (@id, @specialityid, @name, @masterid,
@roomnum)"
SelectCommand="SELECT [id], [specialityid], [name],
[masterid], [roomnum] FROM [class]"
UpdateCommand="UPDATE [class] SET [specialityid] =
@specialityid, [name] = @name, [masterid] = @masterid, [roomnum] =
@roomnum WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
<asp:Parameter Name="id" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="String" />
<asp:Parameter Name="specialityid" Type="String" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="masterid" Type="String" />
<asp:Parameter Name="roomnum" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

error blew

Server Error in '/WebSite1' Application.
--------------------------------------------------------------------------------

'DropDownList1' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1'
has a SelectedValue which is invalid because it does not exist in the
list of items.
Parameter name: value

Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which
is invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +976
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelec t() +32
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.DetailsView.CreateChildC ontrols(IEnumerable
dataSource, Boolean dataBinding) +3174

System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +90
System.Web.UI.WebControls.DetailsView.PerformDataB inding(IEnumerable
data) +31

System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +126
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments
arguments, DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.Perform Select() +154
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
System.Web.UI.WebControls.DetailsView.DataBind() +24
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +91
System.Web.UI.WebControls.DetailsView.EnsureDataBo und() +198
System.Web.UI.WebControls.BaseDataBoundControl.OnP reRender(EventArgs
e) +33
System.Web.UI.WebControls.DetailsView.OnPreRender( EventArgs e) +62
System.Web.UI.Control.PreRenderRecursiveInternal() +148
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint



Dec 15 '05 #4
hi Karl:
the OnItemDataBound event is valid in asp.net 1.1
which event can i hook into when my application is running on asp.net 2.0

thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> дÈëÏûÏ¢ÐÂÎÅ:Oi*************@TK2MSFTNGP15.phx.gbl. ..
You need to do conditional binding. Giving your scenario, I think your
only solution is to hook into the OnItemDataBound event. You can learn
more at:
http://openmymind.net/index.aspx?documentId=8#4.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
thank u,karl
your analyse is very exactly.
but the question is that how can i deel with the unknow value or null
value?

thanks again.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:%2****************@TK2MSFTNGP11.phx.g bl...
It simply sounds like the Eval("MasterId") is returning a value not in
the dropdownlist. Is that possible? Could some of your records possibly
have a null value or some other default or unknown value?

You should try to figure out which MasterId is screwing it up. Also,
you might wanna hook some of this in codebehid, it would be easier to
debug.

Karl

--

Dec 15 '05 #5
OnItemDataBound is still around in 2.0

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ6¸öÔÂ" <re******@msn.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
hi Karl:
the OnItemDataBound event is valid in asp.net 1.1
which event can i hook into when my application is running on asp.net 2.0

thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:Oi*************@TK2MSFTNGP15.phx.gbl. ..
You need to do conditional binding. Giving your scenario, I think your
only solution is to hook into the OnItemDataBound event. You can learn
more at:
http://openmymind.net/index.aspx?documentId=8#4.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
thank u,karl
your analyse is very exactly.
but the question is that how can i deel with the unknow value or null
value?

thanks again.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:%2****************@TK2MSFTNGP11.phx.g bl...
It simply sounds like the Eval("MasterId") is returning a value not in
the dropdownlist. Is that possible? Could some of your records
possibly have a null value or some other default or unknown value?

You should try to figure out which MasterId is screwing it up. Also,
you might wanna hook some of this in codebehid, it would be easier to
debug.

Karl

--


Dec 15 '05 #6
thank u,karl
yes this even is work on the plantform .net2.0
but it does not work on gridview contral
it only work on gridview,isn't it?

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> дÈëÏûÏ¢ÐÂÎÅ:%2***************@TK2MSFTNGP09.phx.gb l...
OnItemDataBound is still around in 2.0

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ6¸öÔÂ" <re******@msn.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
hi Karl:
the OnItemDataBound event is valid in asp.net 1.1
which event can i hook into when my application is running on asp.net
2.0

thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:Oi*************@TK2MSFTNGP15.phx.gbl. ..
You need to do conditional binding. Giving your scenario, I think your
only solution is to hook into the OnItemDataBound event. You can learn
more at:
http://openmymind.net/index.aspx?documentId=8#4.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
thank u,karl
your analyse is very exactly.
but the question is that how can i deel with the unknow value or null
value?

thanks again.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:%2****************@TK2MSFTNGP11.phx.g bl...
> It simply sounds like the Eval("MasterId") is returning a value not in
> the dropdownlist. Is that possible? Could some of your records
> possibly have a null value or some other default or unknown value?
>
> You should try to figure out which MasterId is screwing it up. Also,
> you might wanna hook some of this in codebehid, it would be easier to
> debug.
>
> Karl
>
> --
>



Dec 16 '05 #7
Sorry, never realized you were doing this on a DetailsView. Try the
ItemCreated event
(http://msdn2.microsoft.com/en-us/lib...emcreated.aspx)

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ6¸öÔÂ" <re******@msn.com> wrote in message
news:O3****************@TK2MSFTNGP10.phx.gbl...
thank u,karl
yes this even is work on the plantform .net2.0
but it does not work on gridview contral
it only work on gridview,isn't it?

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:%2***************@TK2MSFTNGP09.phx.gb l...
OnItemDataBound is still around in 2.0

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ6¸öÔÂ" <re******@msn.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
hi Karl:
the OnItemDataBound event is valid in asp.net 1.1
which event can i hook into when my application is running on asp.net
2.0

thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
дÈëÏûÏ¢ÐÂÎÅ:Oi*************@TK2MSFTNGP15.phx.gbl. ..
You need to do conditional binding. Giving your scenario, I think your
only solution is to hook into the OnItemDataBound event. You can learn
more at:
http://openmymind.net/index.aspx?documentId=8#4.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"ÀÏÆÅ»³ÔÐ5¸öÔÂ" <re******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> thank u,karl
> your analyse is very exactly.
> but the question is that how can i deel with the unknow value or null
> value?
>
> thanks again.
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
> net> дÈëÏûÏ¢ÐÂÎÅ:%2****************@TK2MSFTNGP11.phx.g bl...
>> It simply sounds like the Eval("MasterId") is returning a value not
>> in the dropdownlist. Is that possible? Could some of your records
>> possibly have a null value or some other default or unknown value?
>>
>> You should try to figure out which MasterId is screwing it up. Also,
>> you might wanna hook some of this in codebehid, it would be easier to
>> debug.
>>
>> Karl
>>
>> --
>>



Dec 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
2
by: Moon | last post by:
Seems I still haven't got the hang of all those window generating code in Javascript. I've got a page with about 15 photo thumbnails. When you click on a thumbnail a new window pops up which shows...
86
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that:...
35
by: GTO | last post by:
I do not believe that C# is the future of C++. I also do not believe that adding two thousand new library functions to the standard library is the future of C++. But what is the future of C++? Is...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
7
by: Vic | last post by:
Dear All, I found this code snippet on this list (taken from a nice webpage of a courteous fellow), which I used to filter a form on a combo box. I wanted to repeat the same code to have an...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
36
by: MLH | last post by:
Does Date = Date + 1 mean Date Statement equals Date Function plus 1? And if the answer is Yes, how much actual time is being added to the date function in this assignment?
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.