Thanks I feel a fool for not thinking of that. Regards. Kobus
kbalias
Posts
-
Populate ComboBox with DayOfWeek enum? -
Populate ComboBox with DayOfWeek enum?Good day I am using Visual Studio 2010 to develop a Windows app. I am busy with a module where the user can specify setting for days of the week, for example Mondays the lunch duration is 1 hour, Tuesday it is 30 minutes, and so on. I want to display the days of the week (Sunday, Monday, …) in a ComboBox so that the user can select a day. The DisplayMember must be the name, e.g Monday The ValueMember must be the ordinal number of the day in the DayOfWeek enum, e.g. 1 How do I populate the ComboBox using the DayOfWeek enumerator? I tried:
private void Form1_Load(object sender, EventArgs e)
{
for (int j = 0; j < 7; j++)
{
comboDay.Items.Add((DayOfWeek)j);
}
}private void comboDay_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected Day = " + comboDay.SelectedValue);
}This shows the DayOfWeek names in the combobox, but the SelectedValue is always null. Any suggestions on better ways of doing this? Thanks. Kobus
-
SQL Server Time data type and negative TimeSpan values?Hi I am busy working on a windows application to log working times of staff. The application is being developed using C# with SQL Server 2008 as the backend. I have a [NetTime] column (Time data type) in my table in the database. I get the TimeSpan value by subtracting the official working hours and the actual working hours. This TimeSpan value can be positive or negative. I would like to store this value in the [NetTime] column, but the Time data type does not accept negative values. What is the usual way of dealing with this problem? I will need to do calculations with the values in this column, for example to calculate the net or total time a staff member worked overtime or not. Thank you. Kobus
-
How to use minRequiredPasswordLength and minRequiredNonalphanumericCharacters?Hi I am using Visual Web Developer 2010 Express (with C# as code-behind) to develop a website. I have created a custom MembershipProvider and I have specified that in the web.config that
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"I am not sure where and how to use these values. I have done the following: I have added a
CustomValidator
to the Password textbox in theCreateUserWizard
.<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator_PW" runat="server" ControlToValidate="Password"
OnServerValidate="CustomValidate_PW" ValidateEmptyText="true" Display="Dynamic"
ErrorMessage="" ForeColor="Red" ValidationGroup="RegisterUser">
</asp:CustomValidator>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required."
ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>And a server-side method in the code-behind:
protected void CustomValidate_PW(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;//check if password conforms to minimum password length string pw = RegisterUser.Password; if (pw.Length < Membership.MinRequiredPasswordLength) { cv.ErrorMessage = "Minimum Password length is " + Membership.MinRequiredPasswordLength; args.IsValid = false; } //check if password conforms to required number of nonAlphanumericCharacters if (Membership.MinRequiredNonAlphanumericCharacters > 0) { int count = 0; for (int j = 0; j < pw.Length; j++) { if (!char.IsLetterOrDigit(pw\[j\])) { count++; } } if (count < Membership.MinRequiredNonAlphanumericCharacters) { cv.ErrorMessage = "Password requires " + Membership.MinRequiredNonAlphanumericCharacters + " non-Aphanumeric characters"; args.IsValid = false; } }
}
Is there a better way or better place to do this? All help will be appreciated. Kobus
-
Message to user when email not unique?Hi I have managed to figure it out. I am using the
CreateUserError
event of theCreateUserWizard
.protected void RegisterUser_CreateUserError(object sender, CreateUserErrorEventArgs e)
{
Label labelDuplicateEmail = (Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LabelDuplicateEmail");
labelDuplicateEmail.Text = string.Empty;if (e.CreateUserError == System.Web.Security.MembershipCreateStatus.DuplicateEmail) { labelDuplicateEmail.Text = "Email address already exists in the database."; }
}
Kobus
-
Message to user when email not unique?Hi I am using Visual Web Developer 2010 Express (with C# as code-behind) to develop a website. I have created a custom MembershipProvider and I have specified that in the web.config that
requiresUniqueEmail="true"
. In theCreateUser()
method I check whether the email that the new user has entered is unique and the code works. How do I then display a message to the user in theCreateUserWizard
if the email he has entered is not unique? I thought I could reference theCreateUserWizard
in theCreateUser()
method, but the following does not work:Label labelDuplicateEmail = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LabelDuplicateEmail");
labelDuplicateEmail.Text = "Email already exists in the database.";All help will be appreciated. Kobus
-
Code for Downloading from website problemHi I managed to get this to work. I originally had the code in a try...catch block. When I removed the try...catch it worked perfectly. I cannot explain that. Thanks for all the replies. Kobus
-
Problem with GridView Column Count when databinding programmatically?Hello I am using Visual Web Developer 2010 Express (with C# as code-behind) to develop a website. I am loading data from the database into a DataTable and then I bind the DataTable to GridView with the following code:
GridView_Report.DataSource = reportsTable;
GridView_Report.DataBind();The GridView displays the data correctly with all the columns and rows. On the Page I also have a button that will download the data in the GridView to a .csv file. However there was an error and when I debugged it turns out that the
GridView_Report.Columns.Count
says that the GridView has 0 columns. How can this be when the GridView actually shows about 15 columns in the browser? TheGridView_Report.Rows.Count
is correct with 27 rows. All help will be appreciated. Kobus -
Code for Downloading from website problemHello I am using Visual Web Developer 2010 Express (with C# as code-behind) to develop a website. On one of the pages the user can create a report of the data and I would like the user to be able to download the data as a .csv file. I have written the method to download the data, but the HTML of the page is appended to the data in the downloaded file. When searching for solutions people say the
Response.Clear()
andResponse.End()
must be used in the code, but I have that and it still appends the HTML. The download method is:public void ExportCSV(DataTable data, string fileName)
{
try
{
HttpContext context = HttpContext.Current;context.Response.Clear(); context.Response.ContentType = "text/csv"; context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv"); //write column header names for (int i = 0; i < data.Columns.Count - 1; i++) { if (i > 0) { context.Response.Write(","); } context.Response.Write(data.Columns\[i\].ColumnName); } context.Response.Write(Environment.NewLine); //Write data foreach (DataRow row in data.Rows) { for (int i = 0; i < data.Columns.Count - 1; i++) { if (i > 0) { context.Response.Write(","); } context.Response.Write(row\[i\]); } context.Response.Write(Environment.NewLine); } context.Response.End(); } catch (Exception ex) { throw ex; }
}
Here is part of the file that is downloaded:
HospNumber,LastName,FirstName,DOB,Gender,RaceName,DateDied,AgeAtDeath,HospShort,RTID,
RTNum,RegistrationDate,AgeAtRegDate,OSurvival,Last seen,Next appt,Firm,Clinic,Organ,Part,Histology,Intent,Modality,StGp1,StGp2,T,N,M,Study - Other
90000000,Temp,,18/04/1955 12:00:00 AM,,,,,GSH,61227,2010.1103,14/01/2010 12:00:00 AM,,-1,,,,,,,,,,,,,,,
90001245,TestWeb,,23/02/1983 12:00:00 AM,,,23/06/2011 12:00:00 AM,028,04,00,GSH,,,,,,,,,,,,,,,,,,,,
90003214,TestWeb,,18/01/1983 12:00:00 AM,,,,,GEO,,,,,,,,,,,,,,,,,,,,
900223341,TestWeb,,23/03/1983 12:00:00 AM,,,,,GEO,,,,,,,,,,,,,,,,,,,,
90023541,TestWeb,,23/02/1983 12:00:00 AM,,,,,GEO,,,,,,,,,,,,,,,,,,,,
<script type="text/javascript" language="javascript">alert('Thread was being a -
Deploying website on Windows XP computer?Thanks for the reply. I have IIS on the the XP machine and I have created a Virtual Directory to the website. I can access the website from the XP machine using http://xxx.xxx.xxx.xxx/websitename (where xxx.xxx.xxx.xxx is the IP address of the machine), but when I try to access it from another computer I cannot. It just says cannot display the website. Kobus
-
Deploying website on Windows XP computer?Hi I am using Visual Web Developer 2010 Express to develop a website. I am still busy developing the website, but my boss wants to demo what we have so far at a congress. Is it possible to deploy the website on a temporary basis on a Windows XP Professional computer so that my boss can access it via the internet from the congress venue in another city? Thank you for the help. Kobus
-
How do I do layout of FormView without using tables?Thank you This looks like it can help me. Kobus
-
How do I do layout of FormView without using tables?Good day I am using Visual Web Developer 2010 Express to develop a website. I am using a FormView to edit and display records. I am trying to format the layout of the FormView so that I can arrange my data in the FormView in columns. Something like:
Hosp Number: 100000000
Last name: Mouse First name: Mickey
DOB: 01/01/1923 Admission: 06/06/2011I can do it quite easily using Tables, but I see that most people suggest moving away from using tables to do layout and rather use css based tableless design. I am a bit stuck now. Have done some searching, but even Microsoft’s examples of FormViews use tables. Does anyone have an example for me or a URL where I can go and look? Thank you for the help. Kobus
-
Problem with cascading DropDownLists in a databound DetailsViewHi I am trying to develop a website using ASP.NET 4.0 and Visual Web Developer 2010 Express. I am struggling with cascading DropDownLists in a DetailsView when the DetailsView is bound to a SqlDataSource. I have tried the logic outside the DetailsView and the cascading DropDownLists work fine. The markup for the DropDownLists outside the DetailsView is as follows:
<asp:DropDownList ID="ddlFirms" runat="server" AutoPostBack="True"
AppendDataBoundItems="True" DataSourceID="SqlDataSource_Firms1" DataTextField="Firm"
DataValueField="FirmID"
onselectedindexchanged="ddlFirms_SelectedIndexChanged">
<asp:ListItem Value="">- select -</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource_Firms1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString1 %>"
SelectCommand="SELECT * FROM [Firms] ORDER BY [Firm]"></asp:SqlDataSource><asp:DropDownList ID="ddlClinics" runat="server"
AppendDataBoundItems="True" DataSourceID="SqlDataSource_Clinics1" DataTextField="Clinic"
DataValueField="ClinicID">
<asp:ListItem Value="">- select -</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource_Clinics1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString1 %>"
SelectCommand="SELECT * FROM [Clinics] WHERE ([FirmID] = @FirmID) ORDER BY [Clinic]">
<SelectParameters>
<asp:ControlParameter ControlID="ddlFirms" Name="FirmID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>And the code-behind:
protected void ddlFirms_SelectedIndexChanged(object sender, EventArgs e)
{
//this is to clear the list in ddlClinics before it is repopulated with the relevant list for the selected
//item in ddlFirms
ddlClinics.Items.Clear();
//without this line the initial value was not added
ddlClinics.Items.Add("- select -");
}This works fine. When a listItem is selected in the ddlFirms, only the relevant listItems for that firm is populated in ddlClinics. When I try it in the DetailsView it is not so straight-forward. The problem is that if I try to do the logic exactly as for when the DropDownLists which are not in a DetailsView, it gives me the error: "has a SelectedValue which is invalid because it does not exist in the list of items." When I remove the line
ddlCl
-
Problem with DropDownList and RequiredFieldValidatorThank you prasanta_prince In my RequiredFieldValidator I have set the InitialValue="" and it works great. Regards. Kobus
-
Problem with DropDownList and RequiredFieldValidatorHi In a Sql Server database we have a Patient table and a ReferHospital table. The ReferHospital table is a lookup table. There is a Foreign key column (RefHospID) in the Patient table. In the past the Referring hospital was not a required input field, but it has become a required field for input recently. 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 the ReferringHospital table in the database. So the two things I would like to achieve is: 1.) When an old patient record is loaded and the RefHospID field is null, the DropDownList must accept the null and display the initial value “- select -”. 2.) When a new patient is inserted (or an old patient edited) there must be a validation to check that the initial value “- select -” is not still selected, but that a RefHosp has been selected in the DropDownList. I manage to get these two things working individually but not combined. 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_RefHosp"
DataTextField="HospName" DataValueField="HospID" SelectedValue='<%# Bind("HospID") %>' Enabled="True">
<asp:ListItem Selected="True" Value="">- select -</asp:ListItem>
</asp:DropDownList>The code in bold is to enable the DropDownList to accept null values from the database. (This info I found at http://msdn.microsoft.com/en-us/library/ms366709.aspx ) I also added a RequiredFieldValidator to ensure that a value other than “- select -” is selected.
<asp:RequiredFieldValidator ID="RequiredFieldValidatorDV4" runat="server"
ControlToValidate="DropDownList_HP"
ErrorMessage="Select a referring hospital"
InitialValue="- select -" ValidationGroup="PatientInputGroupDV4"
SetFocusOnError="True"></asp:RequiredFieldValidator>The problem is that without
Selected="True" Value=""
In the ListItem of the DropDownList an exception is thrown which says the DropDownList has “SelectedValue which is invalid because it does not exist in the list of items.” And withSelected="True" Value=""
The RequiredFieldValidator does not complain when ‘- select -’ is -
Problem with a require input field DropDownList if old records have null in this fieldHi 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 accep
-
Problem updating DetailsView when added DropDownListHi I am struggling with updating data from a web page. On the page I have a DetailsView control which is bound to a table in the SQL Server database. I have enabled Editing. One of the fields in the table is a foreign key to a lookup table (for the Referring Hospital) in the database. I would like to have a DropdownList in the DetailsView so that the user can choose the item. I have changed the field to a TemplateField and while the field (“HospID”) is still a TextBox the update to database works. For example when I change the LastName and click ‘Update’, the update reflects in the database. Here is the markup:
<asp:TemplateField HeaderText="HospID" SortExpression="HospID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("HospID") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("HospID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("HospID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />However when I replace the TextBox in the EditTemplate with a DropdownList and try to update, the changes do not reflect in the database. Even if I have just changed the LastName. The markup for the DropdownList is as follows:
<asp:TemplateField HeaderText="HospID" SortExpression="HospID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource_RefHosp" DataTextField="HospShort"
DataValueField="HospID">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("HospID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("HospID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>Even if I just use a basic DropdownList with no databinding the update does not work.
<asp:DropDownList ID="DropDownList_RefHosp" runat="server"
DataTextField="HospShort" DataValueField= -
Using user accounts and permissions from custom database for authentication and authorisation in ASP.NET 4? [modified]Hi everyone I developed a Windows Application for the cancer department I am working in. It is a registry of all the patients that we see in the department and the doctors use it for stats and research. Patients are entered and edited in the system. There is also a reports system where users can create their own custom reports and safe the report parameters for future use. I have done the user accounts such that a user can belong to more that one group. So a user might belong to the ‘Patients Admin’ group, the 'Data Admin' group and to the ‘Reports Admin’ group. Another user might belong to the ‘Patient Edit’ group and ‘Reports Admin’ group. A third user might only belong to the ‘Patient Open’ group. Thus depending on the group they belong to they can access certain areas and forms are only allowed certain actions. In other words some users might be able to access a screen/form to view the information, but cannot edit the information. I am using a SQL Server 2008 Express database as the back-end. The user accounts (usernames and hashed passwords) and the Group details and Permissions details are also stored in the same database. The structure is like the following: CREATE TABLE [dbo].[Groups1] ( [GID] [int] NOT NULL PRIMARY KEY CLUSTERED, [GroupName] [nvarchar](50) NOT NULL, [Description] [nvarchar](150) NULL ) CREATE TABLE [dbo].[Permissions1] ( [PID] [int] NOT NULL PRIMARY KEY CLUSTERED, [Permission] [nvarchar](50) NOT NULL, [Description] [nvarchar](150) NULL ) CREATE TABLE [dbo].[Users1] ( [UsID] [int] NOT NULL PRIMARY KEY CLUSTERED, [Username] [nvarchar](50) NOT NULL, [UPassword] [nvarchar](50) NOT NULL ) CREATE TABLE [dbo].[GroupPermissions1]( [GPID] [int] NOT NULL, [FK_GID] [int] NOT NULL FOREIGN KEY REFERENCES Groups1 (GID), [FK_PID] [int] NOT NULL FOREIGN KEY REFERENCES Permissions1 (PID) ) CREATE TABLE [dbo].[UserGroups1] ( [UGID] [int] NOT NULL, [FK_UID] [int] NOT NULL FOREIGN KEY REFERENCES Users1 (UsID), [FK_GID] [int] NOT NULL FOREIGN KEY REFERENCES Groups1 (GID) ) I was asked to convert this Windows application to a Web application. Due to confidentiality issues regarding patient details I need to do authentication and authorization. Is it possible to use this type of group and permissions structure in a web application? If it is possible the next question is then how easy will it be implement the built-in login controls from ASP.NET with the user accounts, groups, and permissions
-
Publishing Update problemHi I have used Visual Studio 2010 Express to develop a Windows application. I have published the program and the users install it from a shared location on a central computer. I have also done several updates that I have published without any problems. When the users run the program it first checks for updates and so far it has always picked up if there was an update and installed it. The program is installed from a folder '\\MyServer\EPR\Installation\Install\' and the update location is '\\MyServer\EPR\Installation\Updates\'. This morning I tried to roll out a new update. I copied the published files to the Updates folder as I have always done, but when I ran the application it checked for updates, but then it still ran the old version and did not install the new version. The old version is 4.0.3.1 and the new version is 4.0.4.0. Any ideas on what the problem can be? At this stage my morning has been a complete waste and I feel very frustrated. Regards. Kobus