John Bailey said:
I actually usually bind to functions rather than directly to properties,
especially when binding to dates.
The only way in a grid though is to use a template column. You should be
able to change whichever column is in question to a template column, and
then
edit the template. When you edit the template, set the binding to custom
and
specify your method. You may want to also pass the container object so
you
have access to the underlying data.
How would I do this if I have a datagrid like following where I want to
format the date for the 1st column (Posted) using both an inline format
statement or call a function to apply the formatting. Same for the money
field (SalaryMax) :
<asp
ataGrid AllowPaging="true"
AllowCustomPaging="false"
PageSize="10"
PagerStyle-Visible="false"
Visible=false
AllowSorting="True"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="1"
BorderColor="#999999"
style="width:800px">
<headerstyle HorizontalAlign="center" BackColor="#c0edee"
ForeColor="#2FABAD" Font-Bold="true" />
<alternatingitemstyle CssClass="alternateRows" />
<footerstyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Bold="true" />
<pagerstyle BackColor="white" />
<columns>
<asp:BoundColumn DataField="Posted"
HeaderText="Posted"
ReadOnly="true"
Visible="True"
ItemStyle-Width="50px"
ItemStyle-VerticalAlign="Top"
SortExpression="DatePosted">
<asp:BoundColumn DataField="Applied"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top">
<itemstyle ForeColor="red" />
</asp:BoundColumn>
<asp:BoundColumn DataField="SalaryMax"
HeaderText="SalaryMax"
ReadOnly="true"
Visible="true"
ItemStyle-VerticalAlign="Top"/>
</columns>
</asp
ataGrid>
sub SetDateFormat(s as Sender, e as eventargs)
????
end sub
sub SetMoneyFormat(s as Sender, e as eventargs)
e.String.Format("{0:c}",CalculateYearly(Regex.Replace(WagesMin.Text,"\$|\,","")))
end sub
I have been applying the date formats in SQL and it has been mentioned that
it would be better to do this on the client.
How would I apply these and/or put the format directly on the column as
opposed to calling the function?
I am trying to find out how to do both as I do have situations where I need
to do more manipulations that just a format on the field.
Thanks,
Tom