Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
540
XamWebgrid Validations
posted

I need validation for the grid..

I am doing some thing like this

        private TemplateColumn _TempCol = new TemplateColumn();
        private TemplateColumn _TempDescription = new TemplateColumn();

Public View()
{
                _TempCol.Key = "ReportPropertyDto.Value";
                _TempCol.Width = ColumnWidth.Auto;
                _TempCol.HeaderText = StringResource.ValueHeaderText;
                _TempCol.MinimumWidth = 100;

                _TempDescription.Key = "CodeDescription";
                _TempDescription.HeaderText = StringResource.DescriptionHeaderText;
                _TempDescription.Width = ColumnWidth.Auto;
                //_TempDescription.MinimumWidth = 137;
                _TempDescription.ItemTemplate = Resources["ColTextBlock"] as DataTemplate;

                reportPropertiesValueGrid.Columns.Add(_TempCol);
                reportPropertiesValueGrid.Columns.Add(_TempDescription);
                reportPropertiesValueGrid.UpdateLayout();

}

 private void Grid_InitializeRow(object sender, InitializeRowEventArgs e)
{

//here I add  controls to the column based on the datatype
switch (property.SQLDataType.ToLower())
{

                    case "date":
                        {
                            _TempCol.ItemTemplate = Resources["ColDatePicker"] as DataTemplate;
                            break;
                        }
                    case "varchar":
                        {
                            _TempCol.ItemTemplate = Resources["ColText"] as DataTemplate;
                            break;
                        }

}


In Xaml

my grid is bound to custom dto (say LocalDto)


        <DataTemplate x:Key="ColText">
            <TextBox Name="Textbox"  Text="{Binding Path=LocalDto.Value, Mode=TwoWay,ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=Explicit}" HorizontalContentAlignment="Stretch" ></TextBox>
        </DataTemplate>

 

from the initilazeRow()

I am trying throwing error if validation for empty or null string fails

something like this

        public void ValidateButtonTest(string value)
        {
            if(string.IsNullOrEmpty(value))
            {
                throw new Exception("Required field.");
            }
        }

it throws an error.

I need to show red border to text box if validation fails

any help will be appreciated


}