Solved

set default value for asp.net datagrid field in edit mode (c#)

Posted on 2014-10-13
3
508 Views
Last Modified: 2014-10-19
I have a simple c# asp.net datagrid being populated from a SQL table.

I have a a template field that displays a date value from the database.
When the user clicks the edit button, the date field goes in to edit mode as expected.

What I am trying to figure out is how to default the date field to current date if the underlying data field is null.

I can't seem to figure out the correct event to watch.

Thanks, Kevin.
0
Comment
Question by:kevinvw1
  • 2
3 Comments
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 500 total points
ID: 40379474
You can do it in your SQL statement using the ISNULL function. It would look like ISNULL(<your date field>, GETDATE())
0
 

Accepted Solution

by:
kevinvw1 earned 0 total points
ID: 40379772
Hi, thanks for the tip.  I actually wanted it to remain null until the user clicks edit on the grid.  Then the edit field would default to today's date.  

I ended up scraping the datagrid and going to a a gridview and I was able to get it all working as desired.

Here is how I did it -

protected void grdJobProduction_RowEditing(object sender, GridViewEditEventArgs e)
        {
            grdJobProduction.EditIndex = e.NewEditIndex;
            BindData();
            if (((TextBox)grdJobProduction.Rows[grdJobProduction.EditIndex].Cells[7].Controls[1]).Text == "")
            {
                ((TextBox)grdJobProduction.Rows[grdJobProduction.EditIndex].Cells[7].Controls[1]).Text = DateTime.Now.ToString("M/d/yyyy");
            }
        }
0
 

Author Closing Comment

by:kevinvw1
ID: 40389801
My comment fully explains the desired need.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now