Click here to Skip to main content
15,887,435 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: A login problem Pin
Farhad Eft31-Mar-11 21:24
Farhad Eft31-Mar-11 21:24 
AnswerRe: A login problem Pin
C#Coudou31-Mar-11 21:02
C#Coudou31-Mar-11 21:02 
GeneralRe: A login problem Pin
Farhad Eft31-Mar-11 21:23
Farhad Eft31-Mar-11 21:23 
GeneralRe: A login problem Pin
Farhad Eft31-Mar-11 21:26
Farhad Eft31-Mar-11 21:26 
GeneralRe: A login problem Pin
C#Coudou3-Apr-11 22:13
C#Coudou3-Apr-11 22:13 
AnswerRe: A login problem [modified] Pin
davidnz2-Apr-11 10:57
davidnz2-Apr-11 10:57 
AnswerRe: A login problem Pin
SamRST4-Apr-11 21:19
SamRST4-Apr-11 21:19 
QuestionProblem with a require input field DropDownList if old records have null in this field Pin
kbalias31-Mar-11 20:42
kbalias31-Mar-11 20:42 
Hi
I have a DetailsView on the page and I have made one of the fields a TemplateField. In the EditItemTemplate and InsertItemTemplate I have a DropdownList that is databound to a table in my Sql Server database. I wanted to add an initial value to the DropdownList namely “- select -” .

I set the AppendDataBoundItems property to true and added the initial value as a ListItem.

Markup of the DropdownList

<asp:DropDownList ID="DropDownList_HP" runat="server"
    AppendDataBoundItems="True" DataSourceID="SqlDataSource_HP" 
    DataTextField="Hospital" DataValueField="H_ID" SelectedValue='<%# Bind("H_ID") %>' Enabled="True">
    <asp:ListItem>- select -</asp:ListItem>
</asp:DropDownList>   


I also added a RequiredFieldValidator to ensure that a value is selected.

<asp:RequiredFieldValidator ID="RequiredFieldValidatorDV4" runat="server" 
    ControlToValidate="DropDownList_HP" 
    ErrorMessage="Select a referring hospital" 
    InitialValue="- select -" ValidationGroup="PatientInputGroupDV4" SetFocusOnError="True"></asp:RequiredFieldValidator>                            



This works fine for new input. The problem is however that the database already has records that were entered through a Windows Application and many of these records has a null value in this field and exceptions are thrown when I tried to open these records and the system tried to set the SelectedValue of the DropdownList.


After some more searching I found this help http://msdn.microsoft.com/en-us/library/ms366709.aspx

So I changed the ListItem in the DropDownList markup to the following:

<asp:DropDownList ID="DropDownList_RefHospDV4" runat="server"
    AppendDataBoundItems="True" DataSourceID="SqlDataSource_RefHosp" 
    DataTextField="HospShort" DataValueField="HospID" SelectedValue='<%# Bind("HospID") %>' Enabled="True">
    <asp:ListItem Selected="True" Value="">- select -</asp:ListItem>
</asp:DropDownList>                            


This now solved the problem of opening a record where the value is null in the database, BUT now the RequiredFieldValidator is not validating anymore to make sure that a databound item is selected for this field and not the initial value “- select -”. So basically now it is not checking anymore to see if valid input has been entered for the DropDownList and it accepts “- select -” thus it acts as if the field is not a required field anymore.

In short what is required is that I want to make sure that the user enters a valid selection in the DropDownList, but it must also cater for old records that do not have this field entered yet so that those old records can be opened in the DetailsView .

Opening Old records (with null in that field):
When these old records are opened in the DetailsView the DropDownlist should show “- select -” when the value in the database is null.

Saving records (old or new records):
When saving the record in Insert mode or Update mode the RequiredFieldValidator should show that a valid input is not selected if the DropDownList is still on “- select -”.

Does anyone have any solutions for me for the problem.

Regards.

Kobus
AnswerRe: Problem with a require input field DropDownList if old records have null in this field Pin
ktrrzn5-Apr-11 15:39
ktrrzn5-Apr-11 15:39 
QuestionHelp how to get the list of printer in the client computer Pin
C#Coudou31-Mar-11 15:17
C#Coudou31-Mar-11 15:17 
AnswerRe: Help how to get the list of printer in the client computer Pin
Not Active31-Mar-11 16:59
mentorNot Active31-Mar-11 16:59 
GeneralRe: Help how to get the list of printer in the client computer Pin
C#Coudou31-Mar-11 18:07
C#Coudou31-Mar-11 18:07 
GeneralRe: Help how to get the list of printer in the client computer Pin
Not Active1-Apr-11 0:59
mentorNot Active1-Apr-11 0:59 
Questiondocument.getElementById Not work With Masterpage ASP.Net VB Pin
Diyaa Hamza31-Mar-11 10:02
Diyaa Hamza31-Mar-11 10:02 
AnswerRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
El_Programmer31-Mar-11 10:53
El_Programmer31-Mar-11 10:53 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Diyaa Hamza31-Mar-11 11:01
Diyaa Hamza31-Mar-11 11:01 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
El_Programmer31-Mar-11 11:11
El_Programmer31-Mar-11 11:11 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 11:54
mentorNot Active31-Mar-11 11:54 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
El_Programmer31-Mar-11 12:01
El_Programmer31-Mar-11 12:01 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 12:05
mentorNot Active31-Mar-11 12:05 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 12:01
mentorNot Active31-Mar-11 12:01 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Diyaa Hamza31-Mar-11 12:34
Diyaa Hamza31-Mar-11 12:34 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
Not Active31-Mar-11 13:26
mentorNot Active31-Mar-11 13:26 
GeneralRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
ktrrzn5-Apr-11 15:51
ktrrzn5-Apr-11 15:51 
AnswerRe: document.getElementById Not work With Masterpage ASP.Net VB Pin
GenJerDan31-Mar-11 17:27
GenJerDan31-Mar-11 17:27 

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.