473,473 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

javascript referencing datagrid

I have a table within a cell of a datagrid. I am doing updates without
postback to the server using Javascript. I have everything working, except
referencing a table within the datagrid cell.

Here is my datagrid code for the cell;
<asp:TemplateColumn HeaderText="3Fields" ItemStyle-Font-Size="8"
SortExpression="Field1 ASC" ItemStyle-Font-Name="Verdana">
<ItemTemplate>
<table border="0">
<tr>
<td id="Field1"><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem, "Field1") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%# DataBinder.Eval(Container.DataItem,
"Field2") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%# DataBinder.Eval(Container.DataItem,
"Field3") %></b></font>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>

My javascript for referencing the data looks like this;
function UpdateComments(nField1,nField2)
{
for(counter=1;counter<parseInt(NumberOfRecords.out erText)+1;counter++)
{
alert(MyDataGrid.firstChild.childNodes(counter).ch ildNodes(2).field1.innerText)
if (MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText ==
nfield1) and
(MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText == nfield2)
{
MyDataGrid.firstChild.childNodes(counter).childNod es(9).innerText= "Comments
Entered"
}
}
}

I have added an alert to see the value of what I am trying to compare to.
The field1.innerText comes up as an error with null or doesn't exist. If I
just reference the innertext without the project ID, I get all three fields.
I am just trying to reference the first.

How can I reference individual cells within a datagrid cell?

Thank you,
Lyners

Nov 19 '05 #1
3 1933
Hi Lyners,

1- add Runat="server" to your table cells that have Ids “fiedl1” and “field2”
2- add the following javascript function in your page

function FindControls(ControlID, TagName)
{
var ret= new Array(); //an array of all object of tagname within
//the datagrid whose ID = ControlID
var aControls = document.getElementsByTagName(TagName);
if (aControls)
{ for (var i=0; i < aControls.length ; i++)
{
if (aControls[i].id.lastIndexOf(ControlID) == aControls[i].id.length -
ControlID.length)
{

ret.push(aControls[i]);
}

}
}
return ret;
}

3- make the following call to get a collection of the tablecells named field1
var controls = FindControls("field1","td");

4- to update the first row in the grid with newval you would
call controls[0].innerText = newval;

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Lyners" wrote:
I have a table within a cell of a datagrid. I am doing updates without
postback to the server using Javascript. I have everything working, except
referencing a table within the datagrid cell.

Here is my datagrid code for the cell;
<asp:TemplateColumn HeaderText="3Fields" ItemStyle-Font-Size="8"
SortExpression="Field1 ASC" ItemStyle-Font-Name="Verdana">
<ItemTemplate>
<table border="0">
<tr>
<td id="Field1"><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem, "Field1") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%# DataBinder.Eval(Container.DataItem,
"Field2") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%# DataBinder.Eval(Container.DataItem,
"Field3") %></b></font>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>

My javascript for referencing the data looks like this;
function UpdateComments(nField1,nField2)
{
for(counter=1;counter<parseInt(NumberOfRecords.out erText)+1;counter++)
{
alert(MyDataGrid.firstChild.childNodes(counter).ch ildNodes(2).field1.innerText)
if (MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText ==
nfield1) and
(MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText == nfield2)
{
MyDataGrid.firstChild.childNodes(counter).childNod es(9).innerText= "Comments
Entered"
}
}
}

I have added an alert to see the value of what I am trying to compare to.
The field1.innerText comes up as an error with null or doesn't exist. If I
just reference the innertext without the project ID, I get all three fields.
I am just trying to reference the first.

How can I reference individual cells within a datagrid cell?

Thank you,
Lyners

Nov 19 '05 #2
you need to learn javascript syntax. arrays use []'s, not ()'s. the logical
and is &&.


"Lyners" <Ly****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
I have a table within a cell of a datagrid. I am doing updates without
postback to the server using Javascript. I have everything working, except
referencing a table within the datagrid cell.

Here is my datagrid code for the cell;
<asp:TemplateColumn HeaderText="3Fields" ItemStyle-Font-Size="8"
SortExpression="Field1 ASC" ItemStyle-Font-Name="Verdana">
<ItemTemplate>
<table border="0">
<tr>
<td id="Field1"><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem, "Field1") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem,
"Field2") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem,
"Field3") %></b></font>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>

My javascript for referencing the data looks like this;
function UpdateComments(nField1,nField2)
{
for(counter=1;counter<parseInt(NumberOfRecords.out erText)+1;counter++)
{
alert(MyDataGrid.firstChild.childNodes(counter).ch ildNodes(2).field1.innerText)
if (MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText ==
nfield1) and
(MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText ==
nfield2)
{
MyDataGrid.firstChild.childNodes(counter).childNod es(9).innerText=
"Comments
Entered"
}
}
}

I have added an alert to see the value of what I am trying to compare to.
The field1.innerText comes up as an error with null or doesn't exist. If I
just reference the innertext without the project ID, I get all three
fields.
I am just trying to reference the first.

How can I reference individual cells within a datagrid cell?

Thank you,
Lyners

Nov 19 '05 #3
I have not run your example, but it maybe possible that the datagrid is
changing the <td id="Field1"> ... I'd check the output of the datagrid html
has a first troubleshooting step.

--
Jay Douglas
http://www.jaydouglas.com
"Lyners" <Ly****@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
I have a table within a cell of a datagrid. I am doing updates without
postback to the server using Javascript. I have everything working, except
referencing a table within the datagrid cell.

Here is my datagrid code for the cell;
<asp:TemplateColumn HeaderText="3Fields" ItemStyle-Font-Size="8"
SortExpression="Field1 ASC" ItemStyle-Font-Name="Verdana">
<ItemTemplate>
<table border="0">
<tr>
<td id="Field1"><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem, "Field1") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem,
"Field2") %></b></font>
</td>
</tr>
<tr>
<td><font size="0" face="Verdana"><b><%#
DataBinder.Eval(Container.DataItem,
"Field3") %></b></font>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>

My javascript for referencing the data looks like this;
function UpdateComments(nField1,nField2)
{
for(counter=1;counter<parseInt(NumberOfRecords.out erText)+1;counter++)
{
alert(MyDataGrid.firstChild.childNodes(counter).ch ildNodes(2).field1.innerText)
if (MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText ==
nfield1) and
(MyDataGrid.firstChild.childNodes(counter).childNo des(2).innerText ==
nfield2)
{
MyDataGrid.firstChild.childNodes(counter).childNod es(9).innerText=
"Comments
Entered"
}
}
}

I have added an alert to see the value of what I am trying to compare to.
The field1.innerText comes up as an error with null or doesn't exist. If I
just reference the innertext without the project ID, I get all three
fields.
I am just trying to reference the first.

How can I reference individual cells within a datagrid cell?

Thank you,
Lyners

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MattB | last post by:
Is there any way to reference a cell in a datagrid's ItemDataBound event by it's DataItem column name (e.item.DataItem("colname")). I need to set a cell's text to "" based on the contents of it's...
3
by: 2obvious | last post by:
I have a DataGrid containing a TextBox control and a CustomValidator in each row. The CustomValidator fires a function that compares all TextBoxes for equality. The algorithm for comparison is...
0
by: rwoo_98 | last post by:
I am using a repeater, with 3 columns of textboxes with X number of rows. The first two columns are enabled and allows the user to enter in numeric data. The third column contains the sum of the...
2
by: Tim::.. | last post by:
Hi I'm trying to create a little application that shows an image of a user when you mouseover there details in a datagrid. The datagrid is populated from an Active Directory Database and I...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
0
by: ElGordo | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
0
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
3
by: DanG | last post by:
Hi I used to have an ImageButton in my datagrid, and referenced the control in the javascript with: var fld = document.getElementById('datagrid__ctl2_btnEdit'); alert(fld); //returns "" >Good...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code....................................................................................... <script language="javascript"...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.