my table field allows null values. but my code below does not work unless a value is assigned to my variable even though the glable variable is initialised to 0; tried the DBNull.Value - still, it gives me error as the table in question is linked and expecting a value.
protected void gvHotel_SelectedIndexChanged(object sender, EventArgs e)
{
int hotelId = (int)gvHotel.SelectedDataKey.Value;
if (hotelId != null)
{
ViewState["HId"] = hotelId;
}
else
{
hotelId = Convert.ToInt32(DBNull.Value.ToString());
}
}
...
Go to the complete details ...