if the value that is selected from the database is Null it displays an error.. I can put a static list item in there but is there a way to assign the static a Null value or assign a default value?
'DropDownList3' 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: 'DropDownList3' 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.
Sorry still not working.. Can I use something in codebehind. This is in the editTemplate of a gridview so would I put it under the GridView_RowCommand or databound? if possible can you help with the sntax im still learning .net
Protected
Sub Gridview1_RowDataBound(ByVal sender
As
Object,
ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs)
Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow
Then
Dim dm
As DropDownList = e.Row.FindControl("DropDownList3")
'here get the value from the DB if NULL bind a default = "-1" OR something like this?
End
If
End
Sub
cwfontan
Member
178 Points
141 Posts
Drop Down List Selected Value is Null Problem
Dec 17, 2008 06:12 PM|LINK
if the value that is selected from the database is Null it displays an error.. I can put a static list item in there but is there a way to assign the static a Null value or assign a default value?
ecbruck
All-Star
98783 Points
9691 Posts
Moderator
Re: Drop Down List Selected Value is Null Problem
Dec 17, 2008 06:22 PM|LINK
Use a blank ListItem:
<asp:listitem text="" value="" />
Microsoft MVP - ASP.NET
cwfontan
Member
178 Points
141 Posts
Re: Drop Down List Selected Value is Null Problem
Dec 17, 2008 06:25 PM|LINK
i tried that.. I get the following error
'DropDownList3' 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: 'DropDownList3' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Source Error:
ecbruck
All-Star
98783 Points
9691 Posts
Moderator
Re: Drop Down List Selected Value is Null Problem
Dec 17, 2008 06:29 PM|LINK
If the item actually being returned from your database is equal to DBNull.Value, then the blank ListItem SHOULD work.
Microsoft MVP - ASP.NET
cwfontan
Member
178 Points
141 Posts
Re: Drop Down List Selected Value is Null Problem
Dec 17, 2008 06:55 PM|LINK
I looked at the table and the value is Nul unless soem hocus pocus when selected.. here is the dropdown
<asp:TemplateField HeaderText="notify3" SortExpression="notify3"> <EditItemTemplate> <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource2" DataTextField="FullName" DataValueField="userID" SelectedValue='<%# Bind("notify3") %>'> <asp:ListItem Text="" Value="">None</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("notify3") %>'></asp:Label> </ItemTemplate> </asp:TemplateField>cwfontan
Member
178 Points
141 Posts
Re: Drop Down List Selected Value is Null Problem
Dec 17, 2008 08:23 PM|LINK
Sorry still not working.. Can I use something in codebehind. This is in the editTemplate of a gridview so would I put it under the GridView_RowCommand or databound? if possible can you help with the sntax im still learning .net
Protected Sub Gridview1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim dm As DropDownList = e.Row.FindControl("DropDownList3") 'here get the value from the DB if NULL bind a default = "-1" OR something like this? End If End Subcwfontan
Member
178 Points
141 Posts
Re: Drop Down List Selected Value is Null Problem
Dec 17, 2008 08:54 PM|LINK
OK wow i found it.. tricky little property I had to add to the dropdownlist was AppendDataBoundItems="True"
whew.. thanks