I have a GridView where the GridViewColumns are created dynamically. We now have data in a column that can sometimes be null. I have kind of figured out how to use the Converter from the binding to change the value based on the value coming in - but this did not fix it. When I click on the filter It throws the error that must be of type Int64.
Here is the code that builds the column:
Here is the converter:
You can see I commented all most of the code out on the converter. I was just trying to get it to work. The value was coming back as the type - so I'm not sure whats going on there.
So I really have to issues here:
1) How to properly set the converter on the column datamember binding.
2) Why does the filter still recognize the null value even though I set the value to "N/A"
Here is the code that builds the column:
GridViewDataColumn col = new GridViewDataColumn(); col.Header = column.Name; col.DataMemberBinding = binding; col.DataType = column.DataType; col.IsSortable = true; if (column.DataType == typeof(Int64)) { col.DataMemberBinding.Converter = new LongConverter(); }public class LongConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //Int64? convertedValue = (Int64)value; //if (convertedValue.HasValue) //{ // return convertedValue.Value; //} //else //{ // return ""; //} return "N/A"; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value.ToString().ToUpper() == string.Empty) { return new Int64(); } else { return Int64.Parse(value.ToString()); } } }So I really have to issues here:
1) How to properly set the converter on the column datamember binding.
2) Why does the filter still recognize the null value even though I set the value to "N/A"