Use the Databinding event to change the value

Hi,

I use a calendar popup to choose a date in my form.
I bind the SelectedDate properties to show the date from database.

Then my poroblem is : When is null value I want to change the binded value to 1.1.1900

What is the way to intercept the binded value and change it ?

I try to find something around the DataBinding event but didn't find anthing...

Thanks for your help !
krypto2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

djhexCommented:
Show me your code I think you must retrieve the information with sqldatareader and then use the property isdbnull of the datareader.
krypto2000Author Commented:
<ew:CalendarPopup id="CalendarPopup5"
   SelectedDate='<%# DataBinder.Eval(dsWarranty1, "Tables[tb_sav_warranty].DefaultView.[0].wty_estimate_validate_date") %>'>

and after on the onLoad event :

daWarranty.SelectCommand.Parameters["@hdr_index"].Value = (string)Session["hdr_index"];
daWarranty.Fill(dsWarranty1);      

CalendarPopup5.DataBind();

that's it !

but when there is a null value , it raise an convertion error.. I think this control don't accept null value so if I can transform to 1.1.1900 it's great for me ...

thanks
djhexCommented:
First DOnt use dataset.
Second if you use the embedded databinder.eval you dont have a way to control for null values. You must make a method to retrieve it programatically. It seems that you are using the dataset designer.

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

krypto2000Author Commented:
there is not a way to intercept the value like the ItemDataBound property of the datagrid and change it ??
StylezHouseCommented:
Is this from a stored proc?

If so, why not just return 1/1/1900 in the query?


Select IsNull(SomeDateField, "1/1/1900") From tablename
djhexCommented:
No with the calendar.

And why are u using typed datasets? its one of the worst practices for real developers. You should make it all by hand
krypto2000Author Commented:
so okay djhex, what do I have to use, DataView ?
I just use dataSet because I can use it in the IDE to DataBind my controls...
djhexCommented:
sqldatareader is the fastest method. It would be something like this

private void Button1_Click(object sender, System.EventArgs e)
            {
                  cargarCalendario();
      

            }

            private void cargarCalendarios()
            {
                  SqlCommand sqlcmd = new SqlCommand("select date from dates", strconn);
                  SqlDataReader dr = sqlcmd.ExecuteReader();
                  dr.Read();
                  if (dr.IsDBNull(0))
                  {
                        int year=1900;
                        int month=01;
                        int day = 01;
                        DateTime olddate= new DateTime(year, month, day);
                        Calendar1.SelectedDate = olddate;
                        Calendar1.VisibleDate= olddate;

                  }
                  else
                  {
                        Calendar1.SelectedDate = dr.GetDateTime(0);
                        Calendar1.VisibleDate = dr.GetDateTime(0);
                  }
            }
            
            }
      }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
krypto2000Author Commented:
i'll try monday now it's week.end ;-)
djhexCommented:
ok.
StylezHouseCommented:
I'd say points to djhex.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.