小编kri*_*han的帖子

无法将DBNull.Value强制转换为“ System.DateTime”类型,请使用可为空的类型

date为null时出错。错误行-DateTime renewalDate = row.Field(“ RenewalDate”);

protected void GrdV_Projects_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow )
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
        DataRow row = ((DataRowView)e.Row.DataItem).Row;
        DateTime renewalDate = row.Field<DateTime>("RenewalDate");
        if (renewalDate.Date > DateTime.Today)
            e.Row.Cells[7].BackColor = System.Drawing.ColorTranslator.FromHtml("#669B1F");
        else
            e.Row.Cells[7].BackColor = System.Drawing.ColorTranslator.FromHtml("#FF8234");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net datetime casting

4
推荐指数
2
解决办法
8492
查看次数

如何在C#中处理null异常

我得到null异常.虽然我直接超过这个页面.我想处理null异常

C#

string json = "";
if (Request.QueryString["data"] !="")
{
    json = Request.QueryString["data"];

    var req = JsonConvert.DeserializeObject<Request>(json);//getting error in this line
    string requestid = req.requestId;
    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MYSTRING"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    connection.Open();
}
Run Code Online (Sandbox Code Playgroud)

错误

值不能为空.参数名称:value

c# asp.net

2
推荐指数
1
解决办法
913
查看次数

如何在asp.net的网格视图中设置模板字段的宽度

我在网格视图中有模板字段我想将宽度减少到 20 像素,如何在网格视图中减少或设置模板字段的宽度?

<asp:TemplateField HeaderText="Day Id">
                    <ItemTemplate>
                        <asp:Label ID="LblDayId" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DayId") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Label ID="lblEditDayId" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DayId") %>'></asp:Label>
                    </EditItemTemplate>
                    <FooterTemplate >
                        <asp:TextBox ID="txtAddDayId" runat="server" ReadOnly="true"></asp:TextBox>
                    </FooterTemplate>
                </asp:TemplateField>
Run Code Online (Sandbox Code Playgroud)

c# asp.net gridview

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×3

c# ×3

casting ×1

datetime ×1

gridview ×1