Hi experts,
may I know is this the way to convert sqldatetime to string at the grid view footer? Cause there is an error for this word: .RowIndex
DateTime startDate = Convert.ToDateTime(gvContract.DataKeys[e.RowIndex].Value.ToString());
Thanks:D
Loading

Madhu KRank #1,514 · 1.1K reputationPosted Feb 14, 2011, 3:57 AM EST
Becky Bloomwood110 reputationPosted Feb 14, 2011, 4:38 AM EST
Suthish NairRank #92 · 22.8K reputationPosted Feb 14, 2011, 4:46 AM EST
gvContract.DataKeys[e.RowIndex].Value ==> This will be always string.
Convert to DateTime
DateTime startDate = Convert.ToDateTime(gvContract.DataKeys[e.RowIndex].Value).ToString("dd-MMM-yyyy");
Becky Bloomwood110 reputationPosted Feb 14, 2011, 4:57 AM EST
Server Error in '/VRM_WebSite' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Web.UI.WebControls.GridViewCommandEventArgs' does not contain a definition for 'RowIndex' and no extension method 'RowIndex' accepting a first argument of type 'System.Web.UI.WebControls.GridViewCommandEventArgs' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 266: { Line 267: Line 268: DateTime startDate = Convert.ToDateTime(gvContract.DataKeys[e.RowIndex].Value).ToString("dd-MMM-yyyy"); Line 269: Line 270:Source File: c:\Users\Maggie\Desktop\Peggie\Peggie\Deployment Source\Phase 1\Deployment 25 Nov for StarHub\VS Projects Source\VRM_WebSite\app\vrm\ContractManagement.aspx.cs Line: 268
Thks!
Suthish NairRank #92 · 22.8K reputationPosted Feb 14, 2011, 5:33 AM EST
DateTime startDate = Convert.ToDateTime(gvContract.DataKeys[e.CommandArgument].Value).ToString("dd-MMM-yyyy");
or example,
string values = gvContract.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();
or,
Suthish NairRank #92 · 22.8K reputationPosted Feb 15, 2011, 9:54 PM EST