By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

javascript referencing datagrid

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.