1
グリッドビューを持っています。グリッドにID、FirstName、LastName、DateOfBirth、Ageの5つの列があります。 OnRowBound関数に必要な機能を記述しました。グリッドビューページを実行すると、「文字列が有効な日時として認識されません」というメッセージが表示されます。ここでは、グリッドビューの他の列に応じて列を更新できません。
はOnRowBound
protected void UserInfoGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime DOBOnGrid = DateTime.ParseExact(e.Row.Cells[3].Text,"MM/dd/yyyy",null);
Label tAge = (Label)e.Row.Cells[4].FindControl("txtAge");
TimeSpan ts = DateTime.Now - DOBOnGrid;
int CurrAge = ts.Days/365;
tAge.Text = CurrAge.ToString();
}
}
<asp:GridView ID="UserInfoGrid" runat="server" AutoGenerateColumns="False" CellPadding="3"
DataKeyNames="userid" DataSourceID="DataSrcUserInfo"
AllowPaging="True" OnRowDataBound="UserInfoGrid_RowDataBound"
OnRowUpdated="Update" OnRowDeleted="Delete" PageSize="10" >
の機能は、誰もが
おかげで、すべての