954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

datagrid, innertext, javascript, database update

Hi
I have a .aspx page that contains some javascript so that
when a user presses a checkbox another cell in the datagrid is filled with the current date . That works fine

My probelm.... when I have the user press the update button (which does a
post back that loops through the datagrid and updates a database) the
field/cell that is filled by the javascript appears to be blank in my update
code, even though I can see it on the screen.
function getCurrentDateTime(chk, chkId)
{
var checkbox = chk
var lstIndx = chkId.lastIndexOf('chkComplete')
var spanId = chkId.substr(0,lstIndx) + 'lblDate';
var spanText = document.getElementById(spanId);

if (checkbox.checked == true)
{
var currentDate = new Date()
var crDT = currentDate.getDate()+ "/" + currentDate.getMonth() + "/" + currentDate.getFullYear() ;
spanText.innerText=crDT;
spanText.innerHTML=crDT;

}
else
{
spanText.innerHTML='';
}
}


My datagrid is as follows:

vsr
Newbie Poster
7 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Have you tried entering in your own values as well? Try entering in your own date value and see if it is posting correctly. Then get back to us.

Oh, and get rid of the space between onclick and =

onclick ="getCurrentDateTime(this,this.id)"

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

What is also might be, cause I had the same problem when looping through checkboxes to check if they were checked, is the postback variable. On mine, I had to have "if Not Page.IsPostBack then" on my databinder or it did not work. Make sure that when binding your information for checking your checkboxes, that your data is bound on every load, or your viewstate will keep the checkboxes at "false" and it will never be checked.

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

Hi SheSaidImaPregy-

I entered my own values and they got updated fine. I debugged the code the update function works fine.

Thanks.

Hi
I have a .aspx page that contains some javascript so that
when a user presses a checkbox another cell in the datagrid is filled with the current date . That works fine

My probelm.... when I have the user press the update button (which does a
post back that loops through the datagrid and updates a database) the
field/cell that is filled by the javascript appears to be blank in my update
code, even though I can see it on the screen.
function getCurrentDateTime(chk, chkId)
{
var checkbox = chk
var lstIndx = chkId.lastIndexOf('chkComplete')
var spanId = chkId.substr(0,lstIndx) + 'lblDate';
var spanText = document.getElementById(spanId);

if (checkbox.checked == true)
{
var currentDate = new Date()
var crDT = currentDate.getDate()+ "/" + currentDate.getMonth() + "/" + currentDate.getFullYear() ;
spanText.innerText=crDT;
spanText.innerHTML=crDT;

}
else
{
spanText.innerHTML='';
}
}


My datagrid is as follows:

vsr
Newbie Poster
7 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Can you please post your update code, cause it doesn't seem to have a flaw on what you have posted so far.

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

Hi SheSaidImaPregy-

I have added a text box to enter and display date. The value in the text box is getting updated and displayed right.

Thanks.

Hi
I have a .aspx page that contains some javascript so that
when a user presses a checkbox another cell in the datagrid is filled with the current date . That works fine

My probelm.... when I have the user press the update button (which does a
post back that loops through the datagrid and updates a database) the
field/cell that is filled by the javascript appears to be blank in my update
code, even though I can see it on the screen.
This is an urgent request.Any help will be greatly appreciated.

Code behind :

private void Save()
{
string dateCompleted;
Boolean completed ;
int id;

foreach (DataGridItem dgItem in dgCycleCheckList.Items)
{
completed = false;

HtmlInputCheckBox chkCompleted = (HtmlInputCheckBox)dgItem.FindControl("chkComplete");

// Label lblDateCompleted = (Label)dgItem.FindControl("lblDate");
// dateCompleted = lblDateCompleted.Text;

TextBox txtDate = (TextBox)dgItem.FindControl("txtDate");
dateCompleted = txtDate.Text;
id = Convert.ToInt32(dgCycleCheckList.DataKeys[dgItem.ItemIndex]);

if (chkCompleted.Checked == true)
completed = true;

DCycleChecklist dCycleChecklist = new DCycleChecklist();
dCycleChecklist.UpdateCycleChecklist(completed, dateCompleted, id);

}
LoadGrid();
}

protected void btnSaveUp_Click(object sender, EventArgs e)
{
Save();
}












vsr
Newbie Poster
7 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

I solved my problem. After finding the control ((TextBox)dgItem.FindControl("txtDate");)
I am getting the client Id and replacing the "_" with "$" to get the name of the control.
I got it from the viewsource page. I used Request.Form to get the value to update the database.


CODE BEHIND:


private void Save()
{
string dateCompleted;
Boolean completed;
string completedBy;
int id;
string controlPrefix;

foreach (DataGridItem dgItem in dgCycleCheckList.Items)
{
completed = false;

HtmlInputCheckBox chkCompleted = (HtmlInputCheckBox)dgItem.FindControl("chkComplete");


TextBox txtDate = (TextBox)dgItem.FindControl("txtDate");
TextBox txtCompletedBy = (TextBox)dgItem.FindControl("txtCompletedBy");

controlPrefix = txtDate.ClientID;
controlPrefix = controlPrefix.Replace("_", "$");
dateCompleted = Request.Form[controlPrefix];
if (dateCompleted == "")
dateCompleted = null;

controlPrefix = txtCompletedBy.ClientID;
controlPrefix = controlPrefix.Replace("_", "$");
completedBy = Request.Form[controlPrefix];

if (chkCompleted.Checked == true)
completed = true;

id = Convert.ToInt32(dgCycleCheckList.DataKeys[dgItem.ItemIndex]);

DCycleChecklist dCycleChecklist = new DCycleChecklist();
dCycleChecklist.UpdateCycleChecklist(completed, dateCompleted, completedBy, id);

}
LoadGrid();
}


Cycle Checklist










vsr
Newbie Poster
7 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

oh I thought you solved this already! I would have helped otherwise :)

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

Hi SheSaidImaPregy
Thanks, I am sure I will need help again some time.

vsr
Newbie Poster
7 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You