get the value of date picker used in gridview - c#

i have create dynamic datepicker inside gridview. i want to know how to get the values of the datepicker
help me out!!
i have used this line
DateTime date2 = DateTime.Parse(((TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("frmdate_endtime")).Text);

Why not cast the control to the appropriate date/time picker class and take the value from that directly? You shouldn't need to parse the text.

Related

Adding date to Date picker and then bind Date to viewModel in Xamarin.Forms

What would be the way to achieve this?
I pass date value to the Date of DatePicker and it works but later I want to do Date{Binding Value} in Xaml so the selected date is passed to the setter getter for further SQLite insertion. However as soon as I add Date{Binding Value} the first date that is passed is not being passed.

Parse c# DateTime to Kendo DateTimePicker format

I was working on edit of a form. I had stored value returned from Kendo DateTimePicker into SQL Server with smalldatetime data type through DateTime of c#. Now while editing I want to display the stored data into the same DateTimePicker. I realized that c# returns date in the format of 2017-07-05T14:53:00 but Kendo DateTimePicker returns value in the format 7/20/2017 2:00AM. I am trying to set the value of Kendo DateTimePicker to the default value of the model. I have tried the following code but it is not working
kendo.parseDate("#Model.date", "dd-MM-yyyyTHH:mm:ss")
How do I do it?

Is it possible to ignore seconds on date time filtering for RadGridView

I am using Telerik RadGridView with custom filter control.
Item source contains field with DateTime value. I need to filter by date ignoring seconds.
One way is to remove seconds from items source, but it is not possible in my case.
Is there any other way to do it?
Thanks
Like in your xaml if you are using basic filtering just add Filtermemberpath for DateTime value column
telerik:GridViewDataColumn DataMemberBinding="{Binding mydate}" FilterMemberPath="date2"/>
Workaround could be add one more variable in your viewmodel and set it as filtermemberpath for the column
In your View model,
DateTime d = DateTime.Now; //or variable which is storing your datetime value
string sd = d.ToString("MM/dd/yyyy HH:mm");

To Display only current date selected in datetime picker

I have a datetime picker in windows form. When i am selecting a date it shows the last selected date and current date. But i want to shows only current date always. It should not show last selected date and current date(both) on the selection dropdown.
public FieldControl()
{
InitializeComponent();
dtpDate.Value = DateTime.Now;
}
Hello Kumar is right,
but what is sense of selectable date and time component where is only one option to select?
Isn't better to make datetimepicker disabled? At least it's less confusing for user and by default actual date is selected when datetimepicker is dispayed.
Jaroslav
Try this :
you can get just today's date as a DateTime using the Today property:
dtpDate.Value = DateTime.Today;
if you want to show only current date in your datepicker then use this code:
dtpDate.MinDate = dtpDate.MaxDate = DateTime.Now;
For more information
Refer this link
You can't do it on the picker. But you can fake it. Resize the dateTimePicker so it only shows the pick button. Then place it next to a textbox. In the onClose event you write the selected value to the textbox, and set the value of the dateTimePicker back to Today.

Modify Date/Time from SQLDataSource

I have a date column in my database, it's not date time so the values have no time attached.
However, when I drag and drop a SQLDataSource on my page and bind a dropdownlist to it to display the date, it automatically adds a time of 12:00:00 AM.
I know why it does this, but I don't know how to get rid of it. Do I need to bind it from codebehind?
Is there an easy fix to this?
Set DropDownList.DataTextFormatString.
<asp:DropDownList
id="datesList"
runat="server"
dataTextFormatString="{0:dd/MM/yyyy}"/>
Then after DataBinding your control will apply the correct format:
Add format to field or column definition. For example Gridview:
<asp:boundfield datafield="Your_Date_Column" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" />
BTW, other method is to use ViewModel - class which is needed only for displaying data. In this class there is no need to use DateTime or other data types: only string. For example, you can define some displaying defaults here: if value null, show text "UNDEFINED" or what you need. In some cases this approach makes centralized point where you make preparation of data for display.
Can you show your sql query it may be useful .Have you use convert(varchar,date ,103) method to your query
C# doesn't have date datatype and though values from sql(date) datatype is convert to datetime field in c#. So better convert date as nvarchar in sql using convert(varchar,date ,103) though C# treats it as string.

Categories

Resources