T
Tudor
Hello I have a datagrid "dg" which has two template columns. The first
template column contains a button denoted "b" and the second template
column contains a div server control denoted "div" which in turn
contains another grid denoted "dg_second". "dg_second" is bound to
"dg" item data. Of course, for each item from "dg" it is generated a
button "b" and div element "div" which contains a "dg_second". What i
want is to attach a javascript code to "b" in order to alternatively
hide or show the corresponding element "div" from the same line(second
column). Theoretically, it is quite simple to do that: i treat the
itemCreated event of "dg" which is fired for every item creation.
Inside this event, i identify for each item the "b" and "div" elements
and i associate to the "b" element a javascript function having as
argument the ClientID value of the "div" element. The javascript
function will simply hide or show the div element who's id receives in
the parameter. The problem is that in this function, the property
ClientID of "b" and "div" elements DOES NOT return the correct values
that are rendered into html code. More exactly ClientID always returns
"b" and "div" instead of some complicated unique strings. Here it is
the implementation of my itemCreated event
private void itemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem ) {
Button b=(Button)e.Item.FindControl("b");
HtmlGenericControl div= (HtmlGenericControl)e.Item.FindControl("div");
String divClientID=div.ClientID;
String js="javascript:setNewContent('" + divClientID+"');return
false;"; b.Attributes["onclick"]=js; }
}
My purpose is to implement a hierarchical grid display.
I would greately appreciate any qualified help for this matter.
Tudor
template column contains a button denoted "b" and the second template
column contains a div server control denoted "div" which in turn
contains another grid denoted "dg_second". "dg_second" is bound to
"dg" item data. Of course, for each item from "dg" it is generated a
button "b" and div element "div" which contains a "dg_second". What i
want is to attach a javascript code to "b" in order to alternatively
hide or show the corresponding element "div" from the same line(second
column). Theoretically, it is quite simple to do that: i treat the
itemCreated event of "dg" which is fired for every item creation.
Inside this event, i identify for each item the "b" and "div" elements
and i associate to the "b" element a javascript function having as
argument the ClientID value of the "div" element. The javascript
function will simply hide or show the div element who's id receives in
the parameter. The problem is that in this function, the property
ClientID of "b" and "div" elements DOES NOT return the correct values
that are rendered into html code. More exactly ClientID always returns
"b" and "div" instead of some complicated unique strings. Here it is
the implementation of my itemCreated event
private void itemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==
ListItemType.AlternatingItem ) {
Button b=(Button)e.Item.FindControl("b");
HtmlGenericControl div= (HtmlGenericControl)e.Item.FindControl("div");
String divClientID=div.ClientID;
String js="javascript:setNewContent('" + divClientID+"');return
false;"; b.Attributes["onclick"]=js; }
}
My purpose is to implement a hierarchical grid display.
I would greately appreciate any qualified help for this matter.
Tudor