How to insert/update a row/cell in datagrid?
-
I don't understand how to update the row into the Datagrid to display a specific date format ??
[ds is my dataset]
foreach (DataRow r in ds.Tables[0].Rows)
{
string dateString1 = r["First_Resurvey_Date"].ToString();
DateTime dateTime=Convert.ToDateTime(dateString1);
string [] dateStringArray= dateTime.GetDateTimeFormats();r\["First\_Resurvey\_Date"\]= dateStringArray\[6\]; **\[This doesn't work, I cannot just assign the specific value to a datagrid row/cell......I need help on how to do that\] \[dateStringArray\[6\], gives the date format as dd-MMM-YY, which is how I want to display my date in the application\]** NotesLabel.Text= dateStringArray\[6\]; NotesLabel.Visible=true;
}
DataView view = ds.Tables[0].DefaultView;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = true; -
I don't understand how to update the row into the Datagrid to display a specific date format ??
[ds is my dataset]
foreach (DataRow r in ds.Tables[0].Rows)
{
string dateString1 = r["First_Resurvey_Date"].ToString();
DateTime dateTime=Convert.ToDateTime(dateString1);
string [] dateStringArray= dateTime.GetDateTimeFormats();r\["First\_Resurvey\_Date"\]= dateStringArray\[6\]; **\[This doesn't work, I cannot just assign the specific value to a datagrid row/cell......I need help on how to do that\] \[dateStringArray\[6\], gives the date format as dd-MMM-YY, which is how I want to display my date in the application\]** NotesLabel.Text= dateStringArray\[6\]; NotesLabel.Visible=true;
}
DataView view = ds.Tables[0].DefaultView;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = true;:wtf: RTFM This does nothing but attempt to assign the value if the 5th element in the array to the column, it does not do any date formating.
string [] dateStringArray= dateTime.GetDateTimeFormats(); r["First_Resurvey_Date"]= dateStringArray[6];
To format a date you need to do something like DateTime.ToShortDateString or DateTime.ToString(...)
only two letters away from being an asset
-
:wtf: RTFM This does nothing but attempt to assign the value if the 5th element in the array to the column, it does not do any date formating.
string [] dateStringArray= dateTime.GetDateTimeFormats(); r["First_Resurvey_Date"]= dateStringArray[6];
To format a date you need to do something like DateTime.ToShortDateString or DateTime.ToString(...)
only two letters away from being an asset
If you have read the code correctly, then you should notice that I have a string type 'dateString1' variable, which holds the string value of a date type data row from the datagrid**[string dateString1 = r["First_Resurvey_Date"].ToString(); ]. My understanding could be wrong. And then there is a DateTime type variable 'dateTime', which holds the DateTime type value of the String dateString1.[DateTime dateTime=Convert.ToDateTime(dateString1);]. And then the string array dateStringArray contains various date formats of the 'dateTime' variable from which I need to display [6].[string [] dateStringArray= dateTime.GetDateTimeFormats(); ]** I do understand that the formatting doesn't change the datarow from the datagrid. Now once I have got a specific format of the date I want to display to the user, I was looking for a way to display that specific format into the datagrid. Please let me know if there is any way to do that, I hope I conveyed correctly what I want to do. Thanks in advance.
-
If you have read the code correctly, then you should notice that I have a string type 'dateString1' variable, which holds the string value of a date type data row from the datagrid**[string dateString1 = r["First_Resurvey_Date"].ToString(); ]. My understanding could be wrong. And then there is a DateTime type variable 'dateTime', which holds the DateTime type value of the String dateString1.[DateTime dateTime=Convert.ToDateTime(dateString1);]. And then the string array dateStringArray contains various date formats of the 'dateTime' variable from which I need to display [6].[string [] dateStringArray= dateTime.GetDateTimeFormats(); ]** I do understand that the formatting doesn't change the datarow from the datagrid. Now once I have got a specific format of the date I want to display to the user, I was looking for a way to display that specific format into the datagrid. Please let me know if there is any way to do that, I hope I conveyed correctly what I want to do. Thanks in advance.
skhan17 wrote:
I need help on how to do that] [dateStringArray[6], gives the date format as dd-MMM-YY, which is how I want to display my date in the application]
You where not clear in what you were asking for. This appears you are asking how to format a date
skhan17 wrote:
r["First_Resurvey_Date"]=
Nor is it clear for this context that you want a format and not a date. The name seems to imply a date. Override the DataBind event and set the value of the column directly rather trying iterate through the DataTable and change the value.
only two letters away from being an asset
-
skhan17 wrote:
I need help on how to do that] [dateStringArray[6], gives the date format as dd-MMM-YY, which is how I want to display my date in the application]
You where not clear in what you were asking for. This appears you are asking how to format a date
skhan17 wrote:
r["First_Resurvey_Date"]=
Nor is it clear for this context that you want a format and not a date. The name seems to imply a date. Override the DataBind event and set the value of the column directly rather trying iterate through the DataTable and change the value.
only two letters away from being an asset
-
I refer to my original response, RTFM. Understanding the tools you are working with help immensely. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.databound.aspx[^]
only two letters away from being an asset