<dx:GridViewDataDateColumn FieldName="ScheduledTimeForDelivery" Caption="Scheduled Time For Delivery" Width="14%" VisibleIndex="5">
<Settings AutoFilterCondition="Contains" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="True" Wrap="True" />
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt" EditFormatString="dd/MM/yyyy hh:mm tt">
<TimeSectionProperties Visible="true">
<TimeEditProperties EditFormatString="hh:mm tt" EditFormat="Custom"></TimeEditProperties>
</TimeSectionProperties>
<ValidationSettings RequiredField-IsRequired="true" ErrorTextPosition="Bottom" ErrorDisplayMode="Text">
<RequiredField ErrorText="Please enter the Scheduled Time For Delivery" />
</ValidationSettings>
</PropertiesDateEdit>
<EditFormSettings VisibleIndex="3" />
</dx:GridViewDataDateColumn>
I want to disable all previous dates in my Column"ScheduledTimeForDelivery" how to disable it previous dates.
Reference: ASPxGridview - date column
Use the editor's MaxDate and MinDate properties for this purpose. For example:
GridViewDataDateColumn dateColumn = gridView.Columns["ScheduledTimeForDelivery"] as GridViewDataDateColumn;
dateColumn.PropertiesDateEdit.MaxDate = System.DateTime.Now.AddYears(5);
dateColumn.PropertiesDateEdit.MinDate = System.DateTime.Now.AddYears(-5);
Or you can manage to do it in aspx page also with help of documentation..
Disabling specific dates in ASPxDateEdit, in Edit form of ASPxGridView
Hope this help..
use this line in cell editor initialize even
if (e.Column.FieldName == "ScheduledTimeForDelivery")
(e.Editor as ASPxDateEdit).MinDate = DateTime.Now.Date;
Related
<asp:GridView ID="grid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField='id' HeaderText="Id" Visible="False" />
<asp:BoundField DataField='Name' Visible="True" HeaderText="Full Name"/>
<asp:BoundField HeaderText="Monday" />
<asp:BoundField HeaderText="Tuesday" />
<asp:BoundField HeaderText="Wednesday" />
<asp:BoundField HeaderText="Thursday" />
<asp:BoundField HeaderText="Friday" />
</Columns>
</asp:GridView>
<asp:TextBox ID="tbFirstDate" runat="server"></asp:TextBox>
//In the DataTable that is the source for this grid1 I have a column 'date', but in the Grid I need to show weekday with that date (ex. Monday 20.08.2012). I also have a TextBox(tbFirstDate) that defines which day is monday, so using that info I need to calculate the rest of the weekdays, date format is yyyy-mm-dd
I work with PostreSQL, this is the SQL query:
SELECT * FROM Table1
WHERE id1=212 AND date BETWEEN '20.08.2012' AND '24.08.2012'
ORDER BY date
Now this result I want to represent in the grid like this
So basically your actual question is how to change a DateTime's DayOfWeek value by it's distance to a specified first day of week?
Then you could use this method:
public static int Weekday(DateTime dt, DayOfWeek startOfWeek)
{
return (dt.DayOfWeek - startOfWeek + 7) % 7;
}
For example, assuming that the user entered today to specify that Tuesday is the beginning of the week:
DateTime value = new DateTime(2012, 8, 20);
DayOfWeek weekday = (DayOfWeek)Weekday(value, DateTime.Now.DayOfWeek);
Console.Write("normally:{0} changed to:{1}", value.DayOfWeek, weekday);
Demo: http://ideone.com/Zk99b
If this is true you only have to use this method in RowDataBound of the GridView to set the Text of a Label in a TemplateField manually according to the specified date in tbFirstDate and the date value in the DataItem of the GridViewRow. Use GridViewRow.FindControl("LabelID") to get a reference to the Label.
I have a grid like below.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" s
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:ButtonField DataTextField="Name" HeaderText="Name" />
<asp:BoundField DataField="ArrDate" DataFormatString="{0:MM/dd/yyyy}"
HeaderText="Arr Date" />
<asp:BoundField HeaderText="Dep Date" DataField="DepDate"
DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField HeaderText="Mail" DataField="Mail" />
<asp:BoundField HeaderText="Status" DataField="Status" />
<asp:BoundField DataField="ResId" HeaderText="ResId" Visible="False" />
</Columns>
</asp:GridView>
In Code Behind:-
try
{
string text = GridView1.Rows[2].Cells[5].Text;
ScriptManager.RegisterStartupScript(this, GetType(), "Message", "alert('ResId = " + text + ".');", true);
}
catch { }
Now the message shows - RegId =.
I can't get the value. So I change the RedId BoundField as vissible. Now I got the Value.
that is RegId =6.
I have two issue now -
1) How to get the RegId value in Non Visible Column.
2) How I find the Row value which i click... bzs the only i can change the ROWVALUE in code..
string text = GridView1.Rows[ROWVALUE].Cells[5].Text;
That is certainly not the right way to do it. You might want to look at using DataKeys to achieve this. With current approach, when you add a new column to your grid your code will fail.
Add your RegId column inside DataKeys property on your gridview
Reference your gridview datakey for the current row in codebehind like this
int regId= Convert.ToInt32(YourGridview.DataKeys[rowIndex]["RegId"].ToString());
I am displaying my data in a devexpress gridview. One of the column is state value. When the grid is edited, I have to show the state in a combobox, so that the user could change the state by choosing a different state. Currently it is displayed in a textbox, since it is the default. Essentially when the user clicks the edit button, a combobox should be displayed as part of the edit controls, and the combobox should be populated with all possible states in the codebehind and the selected value should be the initial value on the grid. It is very easy do it in MS gridview. But I couldn't see any sample code for how to do it in the devexpress gridview.
Thanks
Use GridViewDataComboBoxColumn. Declare datasource and attach it to combo box column or populate it in code behind. This example contains both variants.
You can also take a look at DevExpress grid editing demos.
<dx:GridViewDataTextColumn FieldName="FieldName" VisibleIndex="4">
<EditItemTemplate>
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" DataSourceID="newDataSource" >
</dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
You'll need to set the datasource so you'll get the list of values
If you don't have a data source and want to include the combo box items in your code, here's another way to create the column:
<dx:GridViewDataComboBoxColumn FieldName="QAAproval" VisibleIndex="11" Width="30px">
<PropertiesComboBox>`enter code here`
<Items>
<dx:ListEditItem Text="GENERIC" Value="GENERIC" />
<dx:ListEditItem Text="FAIR" Value="FAIR" />
<dx:ListEditItem Text="VSE" Value="VSE" />
<dx:ListEditItem Text="ECAV" Value="ECAV" />
<dx:ListEditItem Text="FMMDS" Value="FMMDS" />
<dx:ListEditItem Text="CLEAR" Value="CLEAR" />
</Items>
</PropertiesComboBox>
<CellStyle Font-Size="XX-Small">
</CellStyle>
</dx:GridViewDataComboBoxColumn>
Edit the GridView Template, and in the EditTemplate of the field, add the dropdownbox. It might come to look like this
<dx:GridViewDataTextColumn Caption="Field Name"
FieldName="FieldName" VisibleIndex="3">
<EditItemTemplate>
<cc1:DropDownList ID="DropDownList1" runat="server">
</cc1:DropDownList>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
So when you edit that row, it will show the DDL
I have used the following code to have combo box in the aspxgridview.
I hope this example helps :
<dx:GridViewDataComboBoxColumn FieldName="DatabaseFieldName" Settings-FilterMode="DisplayText"
Width="3%" VisibleIndex="3" Visible="True" Caption="Priority" Settings-AutoFilterCondition="Contains"
HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center" CellStyle-HorizontalAlign="Center"
CellStyle-VerticalAlign="Top">
<PropertiesComboBox ValueType="System.String" DataSourceID="objDataSourceID"
Width="200px" Height="25px" TextField="TextFieldName" ValueField="ValueFieldName"
IncrementalFilteringMode="StartsWith">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
I am using devexpress asp:GridView in asp.net with two columns: "status" and "percentage"
The column "status" is a GridViewDataComboBoxColumn which contain two values: "progress" and "completed"
The column "percentage" is a GridViewDataColumn.
What I want to do is:
If I select completed in status then the percentage should display the text '100'.
but I don't know how to trigger combobox events which is present inside asp:GridView
The code I have (so far) is:
<dxwgv:ASPxGridView ID="gridviewTaskProg" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSourceTasks"
onbeforeperformdataselect="gridviewTaskProg_BeforePerformDataSelect"
onrowupdating="gridviewTaskProg_RowUpdating" KeyFieldName="intProgressID"
oninitnewrow="gridviewTaskProg_InitNewRow"
onrowinserting="gridviewTaskProg_RowInserting"
oncancelrowediting="gridviewTaskProg_CancelRowEditing"
onstartrowediting="gridviewTaskProg_StartRowEditing">
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataDateColumn FieldName="StartDateTime" VisibleIndex="1">
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt"
EditFormat="Custom" EditFormatString="dd/MM/yyyy hh:mm tt"></PropertiesDateEdit>
</dxwgv:GridViewDataDateColumn>
<dxwgv:GridViewDataDateColumn FieldName="EndDateTime" VisibleIndex="2">
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt"
EditFormat="Custom" EditFormatString="dd/MM/yyyy hh:mm tt"
dateonerror="Today"></PropertiesDateEdit>
</dxwgv:GridViewDataDateColumn>
<dxwgv:GridViewDataSpinEditColumn FieldName="Percentage" VisibleIndex="3">
<PropertiesSpinEdit DisplayFormatString="g" NumberFormat="Custom"></PropertiesSpinEdit>
</dxwgv:GridViewDataSpinEditColumn>
<dxwgv:GridViewDataComboBoxColumn FieldName="Status" VisibleIndex="4">
<PropertiesComboBox ValueType="System.String"><Items><dxe:ListEditItem Text="Progress" Value="Progress" /><dxe:ListEditItem Text="Completed" Value="Completed"/></Items></PropertiesComboBox>
</dxwgv:GridViewDataComboBoxColumn>
<dxwgv:GridViewDataMemoColumn Caption="Remarks" FieldName="Remarks"
VisibleIndex="5">
</dxwgv:GridViewDataMemoColumn>
</Columns>
</dxwgv:ASPxGridView>
Set grid ClientInstanceName to "grid1" (or any other name, just replace it in my code). Change status combo box column as follows:
<dxwgv:GridViewDataComboBoxColumn FieldName="Status" VisibleIndex="4">
<PropertiesComboBox ValueType="System.String">
<Items>
<dxe:ListEditItem Text="Progress" Value="Progress" />
<dxe:ListEditItem Text="Completed" Value="Completed"/>
</Items>
<ClientSideEvents
SelectedIndexChanged="function(s,e) {
if(s.GetValue()=='Completed')
grid1.GetEditor('Percentage').SetValue(100);
}"
/>
</PropertiesComboBox>
</dxwgv:GridViewDataComboBoxColumn>
How can i change the readonly property of 'percentage'?
#Filip: Exactly!
<ClientSideEvents SelectedIndexChanged="function(s, e) {
if(s.GetValue() == 'Completed') {
var txtEditor = grid1.GetEditor('Percentage');
txtEditor.SetValue(100);
txtEditor.SetEnabled(false);
}
}" />
For some reason i can not format the text of my date in a gridview
<asp:BoundField DataField="deptdate" HeaderText="Departure Date" dataformatstring="{0:ddd, MM/d/yyyy}" htmlencode="False" SortExpression="deptdate" />
I still get this:
May 10 2011 12:00AM
I DID NOT SET MY FIELD TO DATETIME IN THE DATABASE...DOY
Have you tried this approach?
http://peterkellner.net/2006/05/24/how-to-set-a-date-format-in-gridview-using-aspnet-20using-htmlencode-property/
<asp id="GridView1" runat="server" :GridView>
<columns>
<asp headertext="CreationDate" dataformatstring="{0:M-dd-yyyy}"
datafield="CreationDate" :BoundField HtmlEncode="false" />
</columns>
You can use DataFormatString="{0:d}" for short date format in your column definition.
Since Q2 2013 the RadHtmlChart can be databound to DateTime objects, so that XAxis Labels, Series Labels and ToolTips can be formatted to the desired date format. More information on formatting dates is available in Date Axis article: http://www.telerik.com/help/aspnet-ajax/htmlchart-date-axis.html