I'm doing this website for a school project, and when I run this website I have a GridView where I select one registry, then it opens the FormView with all the details about the selected registry
Image of the website working
Now, when I hit that Edit on the FormView it gives me the following error:
'ddl_SelectMae' has a invalid SelectedValue because it does not exist in the list of items. Parameter name: value
I know that, this error appears because the value on field "Mãe" is null, but I saw the database and that value can be null. (Same error applies to the "Pai" and "Comprador" field)
Here the part of the code where error happens, I can put all the code if needed
<asp:FormView ID="fv_Alteracoes" runat="server" DataKeyNames="idCao" DataSourceID="SqlDS_InsEdiDel">
<EditItemTemplate>
<table>
<tr>
<td>Mãe:</td>
<td>
<asp:DropDownList ID="dll_SelectMae" runat="server" DataSourceID="SqlDS_ListarMae" DataTextField="idCao" DataValueField="idCao"
SelectedValue='<%# Bind("Mae") %>'>
</asp:DropDownList>
<asp:SqlDataSource runat="server" ID="SqlDS_ListarMae" ConnectionString='<%$ ConnectionStrings:ConnectionString %>'
SelectCommand="SELECT [idCao], [Nome] FROM [tbl_Cao] WHERE ([Sexo] = 'F')">
</asp:SqlDataSource>
</td>
</table>
<asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateButton" CausesValidation="True" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>
If I do the same but with a registry with all the details filled the website works 100% as I want
Image of website working perfectly
Can someone help me how to stop that error and keep the DropDownList to edit the fields?
PS: Sorry about my English but I am Portuguese, thank you for help
Change Your Data Source so that null can be allowed as :
SELECT [idCao], [Nome] FROM [tbl_Cao] WHERE ([Sexo] = 'F')
union
Select null,'None'
Related
I am using master pages, update panel, AJAX Tab container and also modalpopup extenders and other AJAX validation controls. The line that is bold for Termination Reaon has a problem. I need to have <asp:ListItem Text="Select Contract Termination Reason.." Value=""></asp:ListItem> to control the error:
'ddlContractTerminationReason' has a SelectedValue which is invalid because it does not exist in the list of items"
It works but suddenly it started getting erased while trying to make some other changes to the application. If I try to type that again as soon as I click on Save, it gets erased and saves the file. My network administrator reinstalled everything for me assuming that some virus problem but looks like something else is causing this. Any help on this greatly appreciated.
<tr>
<td>
<asp:DropDownList ID="ddlContractTerminationReason" runat="server" AppendDataBoundItems="True" CausesValidation="True" CssClass="dropdown extralong" DataSourceID="dsTerminationReason" DataTextField="ReasonDescription" DataValueField="TerminationReasonID">
<asp:ListItem Text="Select Contract Termination Reason.."></asp:ListItem>
</asp:DropDownList>
<asp:CustomValidator ID="cusValTerminationReason" runat="server" ClientValidationFunction="RequireTerminationReason" ControlToValidate="ddlContractTerminationReason" ErrorMessage="Please enter Termination Reason OR Other Resson, if the Contractor is Terminated!" OnServerValidate="ServerValidateTerminationDate" SetFocusOnError="True" Text="*" ValidateEmptyText="True" ValidationGroup="ContrMasterGroup"></asp:CustomValidator>
<asp:SqlDataSource ID="dsTerminationReason" runat="server" ConnectionString="<%$ ConnectionStrings:Conn %>" SelectCommand="SELECT [TerminationReasonID], [ReasonDescription] FROM [TerminationReasons] ORDER BY [ReasonDescription]"> </asp:SqlDataSource>
</td>
<td class="rightalign">
<asp:Label ID="lblOtherContractTerminationReason" runat="server" CssClass="lbl" Text="if Others, Explain:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtOtherContractTerminationReason" runat="server" CssClass="long" TextMode="MultiLine"></asp:TextBox>
</td>
<td> </td>
</tr>
After your DataBind execute this code
ddlContractTerminationReason.DataBind();
ddlContractTerminationReason.Items.Add("Select Contract Termination Reason..");
I have the following asp.net DropDownList:
<asp:DropDownList ID="ddlRole" runat="server" DataSourceID="dsRole"
DataTextField="RoleCode" DataValueField="ID" Font-Names="Verdana" Font-Size="11px"
ForeColor="#2D2D2D" ClientIDMode="Static" Width="120px" CssClass="selectedRole"
OnDataBound="ddlEntity_DataBound" AppendDataBoundItems="true" >
<asp:ListItem Value="-1">--- Select ---</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="dsRole" runat="server" SelectMethod="GetList" TypeName="Roles"
OldValuesParameterFormatString="original_{0}"></asp:ObjectDataSource>
I get the "SelectedValue is Invalid Because it does not Exist in the List of Items" error, stating 'value' is incorrect. The ID I'm referencing is 1 and it definitely exists in the DB where I'm calling from.
I've tried solutions to this problem as cited on the internet and other forums, but I still get the same error. I'm assuming this has something to do with the fact that my SelectedValue starts off at -1?
Any suggestions?
I decided to do so to "Select" was the first line in the transmitted data set. You can do it with UNION in MSSQL.
Request this has turned out like this:
SELECT '-1' AS id, 'Select' AS name UNION ALL SELECT id, name FROM users
Must give a column alias, or DropDownList simply does not understand where the id, and where the name
<asp:DropDownList ID="MainCat" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="id">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1%>"
SelectCommand="SELECT id,name FROM users">
</asp:SqlDataSource>
I need to do the same suit
I'm a newbie when it comes to asp.net, so grateful for any help.
I have a simple data bound drop down list, with a details view control. I can select a value from the list, hit update and the correct value gets written to the database. Problem is, the control the automatically "resets" to display the 1st value in the list. This would confuse the user and make them think they'd selected the 1st value prior to the update.
The only code-behind code in relation to this drop down list can be found in the ItemUpdating method of the details view control, as follows:
DropDownList ddlLoc = (DropDownList)dvYourProfile.FindControl("ddlLocation");
e.NewValues["PreferredLocation"] = ddlLoc.SelectedValue;
And here's the code form the aspx page
<asp:TemplateField HeaderText="Preferred Location"
SortExpression="PreferredLocation">
<ItemTemplate>
<asp:DropDownList Text='<%# Bind("PreferredLocation") %>' DataSourceID="dsStaticDate" ID="ddlLocation" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList DataValueField='PreferredLocation' DataSourceID="dsStaticDate" ID="ddlLocation" runat="server" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList DataValueField='PreferredLocation' DataSourceID="dsStaticDate" ID="ddlLocation" runat="server" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:SqlDataSource ID="dsStaticDate" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
SelectCommand="SELECT * FROM StaticData" />
You need to bind form the code behind. The out-of-the-box behavior of binding on the aspx page with the SqlDataSource does not allow you to stop the rebinding of the DropDownList after an event occurs.
I am helping my daughter build an asp.net website that has an Access database. We are using a DataList with a couple fields inside the ItemTemplate. The one that is giving me trouble is the Hyperlink. The code is below. When the page loads the hyperlink renders like this:
<a id="ContentPlaceHolder1_DataList1_lnk_6" href="#http://www.washingtonfaire.com/#" target="_blank">Washington Midsummer Renaissance Faire</a>
But when I click on the link, it tries to navigate to "http://localhost:1852/BOOMPiratesB/Raids.aspx#http://www.washingtonfaire.com/#"
What are we doing wrong?
Here is our code.
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:HyperLink id="lnk" runat="server" NavigateUrl='<%# Eval("Link") %>' Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "VenueName")%>'>
</asp:HyperLink>
<br />
<asp:Label ID="DateTextLabel" runat="server" Text='<%# Eval("DateText") %>' />
<br />
<asp:Label ID="CityStateLabel" runat="server" Text='<%# Eval("CityState") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/my.mdb"
SelectCommand="SELECT [VenueName], [Link], [DateText], [Season], [DateStart], [CityState] FROM [qpgRaid]">
</asp:AccessDataSource>
I cannot see where the extra # signs are coming from. They don't appear to be in the field in the table.
It's very puzzling. And insight would be most appreciated.
Have a look at this question
I guess you are using an access hyperlink column to store the link. If you convert it to a text column it should start working fine, or you may have to strip the '#'s manually.
In Dynamics ax Enterprise Portal I have created a templatefield in AxGridView. Seems everything ok, but when i try to enter some value to this textbox (manually or through lookup), it doesnt bind to ReqPo!ItemId field. Checked that with info(strfmt("%1", ReqPo.ItemId))); in validateWrite method on ReqPo dataset - it prints nothing; What i'm missing?
<asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="<%$ AxLabel:#SYS12836 %>" Visible="true">
<EditItemTemplate>
<asp:TextBox runat="server" ID="TextBoxFilterItemId" CssClass="AxInputField"
Columns="<%$ AxDataSet:ReqTransPo.ReqTrans.ReqPo!ItemId.DisplayLength %>"
Enabled="<%$ AxDataSet:ReqTransPo.ReqTrans.ReqPo!ItemId.AllowEdit %>"
MaxLength="<%$ AxDataSet:ReqTransPo.ReqTrans.ReqPo!ItemId.StringSize %>"
Text='<%# Bind("[ReqPo!ItemId]") %>'>
</asp:TextBox>
<dynamics:AxLookup
ID="AxLookup3" runat="server" OnLookup="Item_lookup" TargetControlId="TextBoxFilterItemId"
CssClass="AxLookupButtonBF" HoverCssClass="AxLookupButtonHoverBF" ShowFilter="True">
</dynamics:AxLookup>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ItemIdLabel" runat="server" Text='<%# Bind("[ReqPo!ItemId]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I assume you are using the ItemId field from the table ReqPo. If you locate that field in the Data Dictionary you will discover that the field does not allow editing.
As AxGridView only supports editing, which leads me to the conclusion that you are trying the break the data integrity rules of the application.
if this is the case, it is obviously not possible.