Solved

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

Posted on 2014-10-13
3
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Analysis 7 59
Moving away from Access 2003 adp files 4 47
C#line chart with data on Y and time on X-axis 3 32
SQL Query 20 18
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

734 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