I am creating a online car booking system, where a user is able to rent a car by per hour or all day. Below is the form i have created using formview:

[IMG]http://i697.photobucket.com/albums/vv333/POLO_GTI_6N2/booking.jpg[/IMG]

And here is the C# code i have created so far to transfer the data to the database. What i want to do is:

1) For AllDay checkbox when checked then PerHour checkbox cannot be checked, and vise versa. Also the depending on what checkbox has been checked then "All Day" or "Per Hour" is saved under the "Rent_type" column in database.
2) If checkbox for All Day is checked then the textbox for entering hours into Per Hour is disabled. If checkbox for Per Hour is checked then the textbox for entering number of days is disabled.
3) If i put in a calender called "Calendar1" for the "Date" field how can i make the selected date on the calendar appear in the "Date" textbox.

Coding in C#:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class User_Booking1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void InsertButton_Click(object sender, EventArgs e)
    {
        DropDownList _CarID = FormView1.FindControl("CarDropDown") as DropDownList;
        TextBox _Firstname = FormView1.FindControl("FirstnameTextBox") as TextBox;
        TextBox _Surname = FormView1.FindControl("SurnameTextBox") as TextBox;
        TextBox _Contact_number = FormView1.FindControl("Contact_numberTextBox") as TextBox;
        TextBox _Rent_type = FormView1.FindControl("Rent_typeTextBox") as TextBox;
        TextBox _Date = FormView1.FindControl("DateTextBox") as TextBox;
        TextBox _Total_hours = FormView1.FindControl("Total_hoursTextBox") as TextBox;
        TextBox _Total_days = FormView1.FindControl("Total_daysTextBox") as TextBox;
        TextBox _Time = FormView1.FindControl("TimeTextBox") as TextBox;

        SqlDataSource1.InsertParameters["CarID"].DefaultValue = _CarID.SelectedValue;
        SqlDataSource1.InsertParameters["Firstname"].DefaultValue = _Firstname.Text;
        SqlDataSource1.InsertParameters["Surname"].DefaultValue = _Surname.Text;
        SqlDataSource1.InsertParameters["Contact_number"].DefaultValue = _Contact_number.Text;
        SqlDataSource1.InsertParameters["Rent_type"].DefaultValue = _Rent_type.Text;
        SqlDataSource1.InsertParameters["Date"].DefaultValue = _Date.Text;
        SqlDataSource1.InsertParameters["Total_hours"].DefaultValue = _Total_hours.Text;
        SqlDataSource1.InsertParameters["Total_days"].DefaultValue = _Total_days.Text;
        SqlDataSource1.InsertParameters["Time"].DefaultValue = _Time.Text;

        SqlDataSource1.Insert();

        Response.Redirect("Booking2.aspx");
    }
    protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

    }
    protected void AllDayCheckBox_CheckedChanged(object sender, EventArgs e)
    {

    }
    protected void PerHourCheckBox_CheckedChanged(object sender, EventArgs e)
    {

    }
}

For questions 1-2 and maybe 3, these things can be handled client side with JavaScript and/or a library such as jQuery. Are you familiar with either?

For #3, I suspect that in your code behind, on the page_load function you'll need to do something like _Date.text = calender1.selectedValue? Not sure about the calendar properties. Otherwise, you'll have also figure out client side how to handle the onclick event when the user clicks on the calendar day so you can capture that and just fill in the information in the <input/> element for the date.

How would i go by doing that? Is it not possible to put it in the .cs file (the coding above)

Ok, i have changed the Rent type field so insted of check boxes it now has an HTMLSelect menu where the user can select "Per Hour" or "All Day." However the problem i have now is how to i get the selected value from the HTMLselect menu and save it to my database as "Per Hour" or "All Day" depending on what value has been selected. Below is my code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class User_Booking1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void InsertButton_Click(object sender, EventArgs e)
    {
        DropDownList _CarID = FormView1.FindControl("CarDropDown") as DropDownList;
        TextBox _Firstname = FormView1.FindControl("FirstnameTextBox") as TextBox;
        TextBox _Surname = FormView1.FindControl("SurnameTextBox") as TextBox;
        TextBox _Contact_number = FormView1.FindControl("Contact_numberTextBox") as TextBox;
        HtmlSelect _Rent_type = FormView1.FindControl("Rent_type") as HtmlSelect;
        TextBox _Date = FormView1.FindControl("DateTextBox") as TextBox;
        TextBox _Total_hours = FormView1.FindControl("Total_hoursTextBox") as TextBox;
        TextBox _Total_days = FormView1.FindControl("Total_daysTextBox") as TextBox;
        TextBox _Time = FormView1.FindControl("TimeTextBox") as TextBox;

        SqlDataSource1.InsertParameters["CarID"].DefaultValue = _CarID.SelectedValue;
        SqlDataSource1.InsertParameters["Firstname"].DefaultValue = _Firstname.Text;
        SqlDataSource1.InsertParameters["Surname"].DefaultValue = _Surname.Text;
        SqlDataSource1.InsertParameters["Contact_number"].DefaultValue = _Contact_number.Text;
        SqlDataSource1.InsertParameters["Rent_type"].DefaultValue = _Rent_type.Value;
        SqlDataSource1.InsertParameters["Date"].DefaultValue = _Date.Text;
        SqlDataSource1.InsertParameters["Total_hours"].DefaultValue = _Total_hours.Text;
        SqlDataSource1.InsertParameters["Total_days"].DefaultValue = _Total_days.Text;
        SqlDataSource1.InsertParameters["Time"].DefaultValue = _Time.Text;

        SqlDataSource1.Insert();

        Response.Redirect("Booking2.aspx");
    }
    protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

    }
}

The code i have created for the HTMLSelect control "Rent_type" does not work it brings up the error "Object reference not set to an instance of an object."

Also how could i use this control to disable the "Total_hours" or "Total_days" fields. I was thinking of using IF statement but is this possible? and how?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.