1
我有一个gridview,网格有5个不同的列ID,名字,姓氏,DateOfBirth和年龄,gridview可以编辑,所以我想更新Age取决于DateOfBirth列我已经在OnRowBound函数中编写了必要的功能。当我执行网格视图页面时,我得到“字符串不被识别为有效的日期时间”。不能更新列取决于GridView中的其他列
这里是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" >
谁能帮我这个
感谢,