Dynamic Control Event Not Firing Help

S

SteveC

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.cursor='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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top