P
poi
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, the click gets a dataset and
assigns it to the page dataset property. The datagrid is created and
bound and I can click on any row. But on postback, the grid disappears
and I am not able to tell what row was actually clicked.
How do I trap what row was clicked by the user?
Thanks.
Page properties added:
public DataSet _infoSet;
public DataGrid _tempGrid = new DataGrid();
In the OnInit:
this.tempGrid = new DataGrid();
this.tempGrid.EnableViewState = true;
this.tempGrid.ID = "tempGrid";
this.tempGrid.ItemCreated +=new DataGridItemEventHandler(
tempGrid_ItemCreated );
this.tempGrid.ItemCommand += new DataGridCommandEventHandler(
tempGrid_ItemCommand );
this.tempGrid.SelectedIndexChanged += new EventHandler(
tempGrid_SelectedIndexChanged );
this.tempGrid.AllowPaging = false;
this.tempGrid.PageSize = 30;
this.tempGrid.Width = System.Web.UI.WebControls.Unit.Percentage(100);
this.tempGrid.GridLines = GridLines.None;
this.tempGrid.Font.Name = "Tahoma";
this.tempGrid.Font.Size = FontUnit.Point(9);
System.Web.UI.WebControls.ButtonColumn actionCol = new ButtonColumn();
actionCol.ButtonType = ButtonColumnType.LinkButton;
actionCol.HeaderText = "Action";
actionCol.ItemStyle.Width = 40;
actionCol.ItemStyle.Wrap = false;
actionCol.Text = "Get";
actionCol.CommandName = "SelectThis";
actionCol.Visible = false;
this.tempGrid.Columns.Add( actionCol );
This shows the JavaScript alert box:
public virtual void infoGrid_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:alert('" +
dgEventArgs.Item.ItemIndex.ToString() + "')";
dgEventArgs.Item.Attributes.Add( "onclick" , onClickString );
int ty=4;
}
}
But if I change the onClickString to
string onClickString = "javascript:__doPostBack('tempGrid$_" + "ctl" +
dgEventArgs.Item.ItemIndex.ToString() + "$_ctl0','')";
the tempGrid_SelectedIndexChanged never fires.
Help!
TIA
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, the click gets a dataset and
assigns it to the page dataset property. The datagrid is created and
bound and I can click on any row. But on postback, the grid disappears
and I am not able to tell what row was actually clicked.
How do I trap what row was clicked by the user?
Thanks.
Page properties added:
public DataSet _infoSet;
public DataGrid _tempGrid = new DataGrid();
In the OnInit:
this.tempGrid = new DataGrid();
this.tempGrid.EnableViewState = true;
this.tempGrid.ID = "tempGrid";
this.tempGrid.ItemCreated +=new DataGridItemEventHandler(
tempGrid_ItemCreated );
this.tempGrid.ItemCommand += new DataGridCommandEventHandler(
tempGrid_ItemCommand );
this.tempGrid.SelectedIndexChanged += new EventHandler(
tempGrid_SelectedIndexChanged );
this.tempGrid.AllowPaging = false;
this.tempGrid.PageSize = 30;
this.tempGrid.Width = System.Web.UI.WebControls.Unit.Percentage(100);
this.tempGrid.GridLines = GridLines.None;
this.tempGrid.Font.Name = "Tahoma";
this.tempGrid.Font.Size = FontUnit.Point(9);
System.Web.UI.WebControls.ButtonColumn actionCol = new ButtonColumn();
actionCol.ButtonType = ButtonColumnType.LinkButton;
actionCol.HeaderText = "Action";
actionCol.ItemStyle.Width = 40;
actionCol.ItemStyle.Wrap = false;
actionCol.Text = "Get";
actionCol.CommandName = "SelectThis";
actionCol.Visible = false;
this.tempGrid.Columns.Add( actionCol );
This shows the JavaScript alert box:
public virtual void infoGrid_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:alert('" +
dgEventArgs.Item.ItemIndex.ToString() + "')";
dgEventArgs.Item.Attributes.Add( "onclick" , onClickString );
int ty=4;
}
}
But if I change the onClickString to
string onClickString = "javascript:__doPostBack('tempGrid$_" + "ctl" +
dgEventArgs.Item.ItemIndex.ToString() + "$_ctl0','')";
the tempGrid_SelectedIndexChanged never fires.
Help!
TIA