Asp.Net Calendar DateTime and Hour - asp.net

I need to be able to select both the date and the time from an ASP.Net Calendar Control, (instead of just the date). How do I accomplish this?
This is my code so far:
protected void btnEkle_Click(object sender, EventArgs e) {
DateTime selected = Tarih.SelectedDate;
DateTime dt = new DateTime(selected.Year, selected.Month, selected.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
using (KargoTakipEntities kargo = new KargoTakipEntities()) {
KargoTakipSorgu kargoekle = new KargoTakipSorgu { Tarih = dt, }
}
}

Related

filter class with stimulsoft

I designed a report with stimul. In this report there's two types of filters. First one for filtering Date via two text box and other one for filtering class type via dropdown.
Both of them work correctly in stimulsoft designer but dropdown filtering doesn't work in asp.net web page.
http://8pic.ir/images/0klmctx0poxzfud6pjy0.png
public partial class Report : System.Web.UI.Page
{
EsmailEntities db = new EsmailEntities();
protected void Page_Load(object sender, EventArgs e)
{
DrpGrpPro();
}
protected void Button1_Click(object sender, EventArgs e)
{
string con = ConfigurationManager.ConnectionStrings["EsmailEntities"].ConnectionString;
string serverlocation = HttpContext.Current.Server.MapPath(string.Empty);
StiReport report = new StiReport();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("connection", con));
report.Load(serverlocation + "\\Reports\\ReportWithFiltermrt.mrt");
report.Dictionary.Variables["SC"].Value = DropDownList1.SelectedItem.Value;
report.Dictionary.Variables["FromDate"].Value = txtFromDate.Text;
report.Dictionary.Variables["ToDate"].Value = txtToData.Text;
}
void DrpGrpPro()
{
DropDownList1.DataTextField = "ClassName";
DropDownList1.DataValueField = "ClassId";
DropDownList1.DataSource = db.TblClass.ToList();
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("انتخاب کنید", "0"));
}
}

adding number of days in calendar extender

I have been working on a project and I got stuck with a problem i.e I am able to select first and last date using asp.net calendar control but i want it to be done with calendar extender
the code shown as below is for calender control ..please provide me the solution for calendar extender with required modification..............
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Calendar1.SelectionMode = CalendarSelectionMode.DayWeek;
//ArrayList selectedDates = new ArrayList();
string s = Calendar1.SelectedDate.ToShortDateString();
DateTime today = DateTime.Parse(s);
DateTime firstDay = today.AddDays(-(double)(today.DayOfWeek));
DateTime lastDay = today.AddDays(6 - (double)(today.DayOfWeek));
for (int loop = 0; loop < 7; loop++)
Calendar1.SelectedDates.Add(firstDay.AddDays(loop));
lblStartOfWeek.Text = firstDay.ToLongDateString();
lblEndOfWeek.Text = lastDay.ToLongDateString();
lblStartOfWeek.Visible = true;
lblEndOfWeek.Visible = true;
checkLessonPlan();
}
protected void Calendar1_ontextchanged(object sender, EventArgs e)
{
string numberofdays= Convert.ToDateTime(this.TextBox1.Text).DayOfWeek.ToString("d");
DateTime select = Convert.ToDateTime(TextBox1.Text);
lblStartOfWeek.Text = select.AddDays(-Convert.ToInt32(numberofdays)).ToString("dd MMMM yyyy");
lblEndOfWeek.Text = select.AddDays(6-Convert.ToInt32(numberofdays)).ToString("dd MMMM yyyy");
}

highlight selected week of asp.net calendar

I need to highlight the week on base of selected date in asp.net calendar. As we can specify style for the selected date, do asp.net calendar have option to specify style for the entire week of the selected date?
You can use calendar_dayrender event
public void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
e.Day.IsSelectable = false;
DataRow[] rows = Tables.Select(
String.Format(
"Date='{0}' and Month='{1}' and Year='{2}'",
e.Day.Date.Day,
e.Day.Date.Month,
e.Day.Date.Year
)
);
foreach (DataRow row in rows)
{
System.Web.UI.WebControls.Image image;
image = new System.Web.UI.WebControls.Image();
if (somecondition)
{
e.Cell.CssClass = "cssclass";
}
}

How to select Listbox value in asp.net

I have a ListBox in my webpage that is bound from database in this way:
ListBox1.DataTextField = "Text";
ListBox1.DataValueField = "MenuID";
ListBox1.DataSource = SqlHelper.ExecuteReader(DAL.DALBase.ConnectionString, "GetMenu");
ListBox1.DataBind();
I want to get selected item value and used this code but have a error and does not worked.
ListBox1.SelectedValue;
Forgive me if I have problems on how to write because my English is not good.
Can you be more specific on the error you are getting?
Using ListBox1.SelectedValue should work.
For example:
int mySelectedValue = int.Parse(ListBox1.SelectedValue);
or
string mySelectedValue = ListBox1.SelectedValue;
Edit
Added code to ensure the original poster was keeping values in ListBox databound.
protected void Page_Load( object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindListBox();
}
}
private BindListBox()
{
ListBox1.DataTextField = "Text";
ListBox1.DataValueField = "MenuID";
ListBox1.DataSource = SqlHelper.ExecuteReader(DAL.DALBase.ConnectionString, "GetMenu");
ListBox1.DataBind();
}
protected void SomeButton_Click( object sender, EventArgs e)
{
string mySelectedValue = ListBox1.SelectedValue;
}

asp.net data entry form

I want to build a form where users can enter some data in a few text boxes and click the "Add" button and have the the data appear in a grid or something like it. They need to be able to enter multiple rows.
Then when they are done they can click the "Save" button to save the data to the database.
How do I get the data from from the text boxes into the "grid"?
EDIT
Here's what I have so far
protected void Page_Load(object sender, EventArgs e)
{
DataTable myDataTable = new DataTable();
DataColumn dc1 = new DataColumn("Employee");
myDataTable.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("Category");
myDataTable.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("Description");
myDataTable.Columns.Add(dc3);
DataColumn dc4 = new DataColumn("P/S/N");
myDataTable.Columns.Add(dc4);
DataColumn dc5 = new DataColumn("Hours");
myDataTable.Columns.Add(dc5);
DataColumn dc6 = new DataColumn("WeekEnding");
myDataTable.Columns.Add(dc6);
}
protected void btnAddToGrid_Click(object sender, EventArgs e)
{
DataRow row = myDataTable.NewRow();// i'm getting error here sayind myDataTable does not exist
row["Employee"] = LoginName1.ToString();
row["Category"] = ddlCategory.SelectedValue;
row["Description"] = txtDescription.Text;
row["P/S/N"] = ddlPSN.SelectedValue;
row["Hours"] = ddlHours.SelectedValue;
row["WeekEnding"] = txtWeekEnding.Text;
myDataTable.Rows.Add(row);
Ok your first problem from your comment:
i'm getting error here sayind myDataTable does not exist
Is because you defined your table in the Page_Load and then it goes out of scope at the end of the function. It sounds like you don't understand the basic concepts of ASP.NET and what you are trying to do.
Here is a quick and dirty untested solution to your problem but I must stress that you should try and understand why this solution works before trying to extend it or do more in ASP.NET. I hope my 10 minutes of my time helps you get a good start into understanding C# and ASP.NET.
[Serializable]
public class YourData
{
public string Employee { get; set; }
public string Category { get; set; }
public string Description { get; set; }
public string P_S_N { get; set; }
public string Hours { get; set; }
public string WeekEnding { get; set; }
}
// Used to add your list of data to the viewstate cache
// (There are other ways to store data between posts but I am trying to keep it simple)
public void SetYourCachedData(List<YourData> data)
{
ViewState["YourDataCache"] = data;
}
// Used to get your save data so far
public List<YourData> GetYourCachedData()
{
return ViewState["YourDataCache"] == null ?
new List<YourData>() : (List<YourData>)(ViewState["YourDataCache"]);
}
protected void Page_Load(object sender, EventArgs e)
{
// Do nothing
}
protected void btnAddToGrid_Click(object sender, EventArgs e)
{
// Get the data and store it in the ViewState to cache it between post backs
// Assuming one record added with each click.
List<YourData> data = GetYourCachedData();
data.Add(new YourData()
{
Employee = LoginName1.ToString(),
Category = ddlCategory.SelectedValue,
Description = txtDescription.Text,
P_S_N = ddlPSN.SelectedValue,
Hours = ddlHours.SelectedValue,
WeekEnding = txtWeekEnding.Text
});
// You can bind to any type of collection easily.
// You don't need to use a DataTable with a GridView
yourGrid.DataSource = data;
yourGrid.DataBind();
SetYourCachedData(data);
}
protected void btnSaveData_Click(object sender, EventArgs e)
{
// Pull data from the ViewState cache
List<YourData> data = GetYourCachedData();
// Now iterate through data to save it to your database...
// look this up if you don't know how as this is a lot more work.
}
looks like you just need to set the output object's datasource and bind it.
I.e.:
myGrid.datasource = myDataTable
myGrid.databind()
And as Kelsey says -- keep your datatable in scope.
a public dim right above your page_load would be easier, if you just want to try it out. Otherwise, the separate class approach is a good way to go.

Resources