Ask a Question related to ASP.NET General, Design and Development.
-
SteveC #1
Dynamic Control Event Not Firing Help
In my ASP.NEt codebehind, I declare a public var for a DataGrid. Then
in the TextChanged event handler for a TextBox, I create a <div> tag,
stuff it inside the form, then instance a DataGrid and put it inside
the <div> tag.
In the web page, I can click on any row in the grid, and when the page
posts back, the grid goes away. That is good. However, I can't seem
to trap any events or what was actually clicked. Can anyone tell me
what I'm missing.
Thanks.
This is in TextChanged:
// ...get a dataset based on ambiguous text entry....
// ...create HtmlGenericControl for the <div>...
// ...databind the grid...
dataGrid.ItemCommand +=new DataGridCommandEventHandler(
dataGrid_ItemCommand );
dataGrid.ItemCreated +=new DataGridItemEventHandler(
dataGrid_ItemCreated );
dataGrid.SelectedIndexChanged +=new EventHandler(
dataGrid_SelectedIndexChanged );
dataGrid.DataBind();
dataGrid.EnableViewState = true;
private void dataGrid_ItemCreated(object sender, DataGridItemEventArgs
dgEventArgs)
{
if (
dgEventArgs.Item.ItemType == ListItemType.Item ||
dgEventArgs.Item.ItemType == ListItemType.AlternatingItem ||
dgEventArgs.Item.ItemType == ListItemType.SelectedItem
)
{
dgEventArgs.Item.Attributes.Add(
"onmouseover" ,
"this.style.backgroundColor='#00FF99';this.style.c ursor='hand'" );
dgEventArgs.Item.Attributes.Add(
"onmouseout" ,
"this.style.backgroundColor='#FFFFEA';" );
string onClickString =
"javascript:__doPostBack('dataGrid$_" + "ctl"
+ dgEventArgs.Item.ItemIndex.ToString() + "$_ctl0','')";
dgEventArgs.Item.Attributes.Add( "onclick" , onClickString );
}
}
private void dataGrid_SelectedIndexChanged(object sender, EventArgs
eventArgs)
{
Response.Write( sender.ToString() +"<br/>");
Response.Write( eventArgs.ToString() +"..<br/>");
}
private void dataGrid_ItemCommand(object source,
DataGridCommandEventArgs eventArgs)
{
Response.Write( eventArgs.CommandArgument.ToString() );
Response.Write( eventArgs.CommandName.ToString() );
Response.Write( eventArgs.CommandSource.ToString() );
}
And if I "View Source" from within IE, I don't see the <div> tag or
the DataGrid in Notepad, although the grid-in-div shows in the
browser.
Thanks.
SteveC Guest
-
Firing user control event from parent control
Hi, actually you don't need events. all you need is internal or public function exposed by your inner user control(UCSub). you can call that... -
Sophisticated Dynamic DataGrid Not Firing Event ! Desperate !
Help! I made a DataGrid in code behind only. There is no reference to it in the ASPNET page template. With a search button on the web form,... -
Composite Control - Event not firing in child control
Hello: I am experiencing an issue where I have a composite control (TestOuter) composed of more composite (TestInner) controls. When I am... -
Sort not firing PostBack event using Dynamic Columns
I am having a problem with the DataGrid control and sorting, and have found it's realted to if you use dynamic columns or not. If I set the columns... -
Event not firing.adding dynamic controls to Usercontrol.
I am adding controls to the UserControl dynamically and then loading the UserControl Dynamically.But I am facing problem with firing of click event...



Reply With Quote

