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

Dynamic Control Event Not Firing Help

P: n/a
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.
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.