<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.
Related
<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;
I've go a little problem and I can't find a solution.
When the gridview is bound all prices will be shown as Microsoft.Xrm.Sdk.Money instead of its value.
Does anyone know why this happens and how to change it?
Here is my Gridview:
<asp:GridView ID="ProductList"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="ProductList_OnRowDataBound">
<Columns>
<asp:BoundField
HeaderText="Productno."
DataField="ProductNumber"/>
<asp:BoundField
HeaderText="Product"
DataField="Name" />
<asp:BoundField
HeaderText="Price/Unit"
DataField="Price" />
</Columns>
</asp:GridView>
and i fill it with teh following code
Products = (from ppl in priceCatalog.price_level_product_price_levels
join prod in ServiceContext.ProductSet.ToList()
on ppl.ProductId.Id equals prod.ProductId
select new Product()
{
ProductId = prod.ProductId,
ProductNumber = prod.ProductNumber,
Name = prod.Name,
Price = prod.Price,
//Price = ppl.Amount.Value,
PriceLevelId = ppl.PriceLevelId,
SubjectId = prod.SubjectId,
DefaultUoMId = ppl.UoMId
}).ToList();
var product = Products.Where(p => p.SubjectId.Id == filterTo).ToList();
ProductList.DataKeyNames = new[] { "ProductId" };
ProductList.DataSource = product.ToDataTable(XrmContext);
ProductList.DataBind();
At the moment it looks like this:
PNo. Name Price
1 Prod 1 Microsoft.Xrm.Sdk.Money
2 Prod 2 Microsoft.Xrm.Sdk.Money
3 Prod 3 Microsoft.Xrm.Sdk.Money
....
On xrm.cs( generated file for early bind with CRM)
its following:
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("price")]
public System.Nullable<decimal> Price
{
get
{
return this.GetAttributeValue<System.Nullable<decimal>>("price");
}
set
{
this.SetAttributeValue<Microsoft.Xrm.Sdk.Money>("Price", "price", value);
}
}
You can use a TemplateField to display the Value property (that contains the decimal value) of Price field. I added another column to your example
<asp:GridView ID="ProductList"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="ProductList_OnRowDataBound">
<Columns>
<asp:BoundField
HeaderText="Productno."
DataField="ProductNumber"/>
<asp:BoundField
HeaderText="Product"
DataField="Name" />
<asp:BoundField
HeaderText="Price/Unit"
DataField="Price" />
<asp:TemplateField HeaderText="Price/Unit Decimal">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Price.Value") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I'didnt found a working solution.
what i have done so it works:
I created a new class and at this point i used it. now it works:
Products = (from ppl in priceCatalog.price_level_product_price_levels
join prod in ServiceContext.ProductSet.ToList()
on ppl.ProductId.Id equals prod.ProductId
select new ProductClass()
{
ProductId = prod.ProductId,
ProductNumber = prod.ProductNumber,
Name = prod.Name,
Price = prod.Price,
//Price = ppl.Amount.Value,
PriceLevelId = ppl.PriceLevelId,
SubjectId = prod.SubjectId,
DefaultUoMId = ppl.UoMId
}).ToList();
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 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