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.
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.