Click here to Skip to main content
16,015,020 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionCHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values Pin
joelsef27-Jul-06 19:05
joelsef27-Jul-06 19:05 
AnswerRe: CHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values Pin
Ista28-Jul-06 7:43
Ista28-Jul-06 7:43 
GeneralRe: CHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values Pin
joelsef28-Jul-06 8:47
joelsef28-Jul-06 8:47 
GeneralRe: CHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values Pin
Ista28-Jul-06 9:38
Ista28-Jul-06 9:38 
GeneralRe: CHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values Pin
joelsef28-Jul-06 11:17
joelsef28-Jul-06 11:17 
GeneralRe: CHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values [modified] Pin
Ista28-Jul-06 11:19
Ista28-Jul-06 11:19 
GeneralRe: CHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values Pin
Ista28-Jul-06 9:45
Ista28-Jul-06 9:45 
AnswerRe: CHALLENGE: Formview (ObjectDataSource) can't handle nullable types? Handling null values Pin
MichaelF7717-Jul-10 6:32
MichaelF7717-Jul-10 6:32 
There are two solutions depending on whether you specify parameters or pass objects.
If you specify parameters to ODS - it's pretty simple:

void ItemUpdatingProcessor(ObjectDataSource o,FormViewUpdateEventArgs e)
{
    foreach (Parameter param in o.UpdateParameters)
    {
        if (e.NewValues[param.Name] != null && e.NewValues[param.Name].ToString() == string.Empty)
        {
            if ((param.Type == TypeCode.Decimal || param.Type == TypeCode.Double ||
                  param.Type == TypeCode.Int32 || param.Type == TypeCode.Byte ||
                  param.Type == TypeCode.Single || param.Type == TypeCode.DateTime ||
                  param.Type == TypeCode.Boolean) &&
                  param.ConvertEmptyStringToNull == true &&
                 (param.Direction == System.Data.ParameterDirection.Input ||param.Direction == System.Data.ParameterDirection.InputOutput))
            {
                e.NewValues[param.Name] = null;
            }
        }
    }
}


If you are passing objects, then custom method:

protected void FixItemUpdating(string[] ignoredList, FormViewUpdateEventArgs e)
{
    foreach (var key in e.NewValues.Keys)
    {
        if (ignoredList.Contains(key))
            continue;
        if (e.NewValues[key] != null && e.NewValues[key].ToString() == string.Empty)
        {
            e.NewValues[key] = null;
        }
    }
}


And "ignoredList" - list of fields that allow empty strings and not allow nulls ( ended up empty for my projects, but you just never know.
QuestionRadiio Button List Pin
nikeshkumar27-Jul-06 18:43
nikeshkumar27-Jul-06 18:43 
AnswerRe: Radiio Button List Pin
Hy Chanhan28-Jul-06 0:51
professionalHy Chanhan28-Jul-06 0:51 
AnswerRe: Radiio Button List Pin
_AK_28-Jul-06 1:16
_AK_28-Jul-06 1:16 
QuestionShare link of adding row to gridview Pin
blurMember27-Jul-06 15:11
blurMember27-Jul-06 15:11 
AnswerRe: Share link of adding row to gridview Pin
minhpc_bk27-Jul-06 15:28
minhpc_bk27-Jul-06 15:28 
QuestionRe: even superman cant solve gridview Pin
blurMember27-Jul-06 21:40
blurMember27-Jul-06 21:40 
QuestionMobile Agent Pin
Nabeel Younus Khan27-Jul-06 12:22
Nabeel Younus Khan27-Jul-06 12:22 
AnswerRe: Mobile Agent Pin
minhpc_bk27-Jul-06 15:28
minhpc_bk27-Jul-06 15:28 
Questionhow to access my application from other PC asp.net 2.0 issue Pin
Masood Ahmed27-Jul-06 12:07
Masood Ahmed27-Jul-06 12:07 
AnswerRe: how to access my application from other PC asp.net 2.0 issue Pin
minhpc_bk27-Jul-06 15:31
minhpc_bk27-Jul-06 15:31 
GeneralRe: how to access my application from other PC asp.net 2.0 issue Pin
Masood Ahmed27-Jul-06 16:53
Masood Ahmed27-Jul-06 16:53 
AnswerRe: how to access my application from other PC asp.net 2.0 issue Pin
cs856927-Jul-06 21:48
cs856927-Jul-06 21:48 
QuestionASP.NET reports Pin
TheEagle27-Jul-06 11:35
TheEagle27-Jul-06 11:35 
AnswerRe: ASP.NET reports Pin
minhpc_bk27-Jul-06 15:33
minhpc_bk27-Jul-06 15:33 
GeneralRe: ASP.NET reports Pin
TheEagle27-Jul-06 18:39
TheEagle27-Jul-06 18:39 
GeneralRe: ASP.NET reports Pin
minhpc_bk27-Jul-06 19:53
minhpc_bk27-Jul-06 19:53 
QuestionMscorlib error on my machine but not on others Pin
leckey27-Jul-06 11:07
leckey27-Jul-06 11:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.