B
Bruce W.1
My datagrid displays just fine. When I click on a row it posts
back but I can't seem to catch the event to do anything. My
handler never gets called. Can anyone please tell me why?
In the .aspx file:
------------------
<asp
ataGrid id="DataGrid1" runat="server" Width="400px"OnSelectedIndexChanged="DataGrid1_SelectedIndexChanged">
In the code behind:
-------------------
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.ItemCreated += new DataGridItemEventHandler(this.Item_Created);
DataGrid1.SelectedIndexChanged += new EventHandler(this.DataGrid1_SelectedIndexChanged);
dbClass db = new dbClass();
DataSet ds = db.GetList();
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
void Item_Created(Object sender, DataGridItemEventArgs e)
{
e.Item.Attributes.Add ("onmouseover", "this.style.backgroundColor='beige';this.style.cursor='hand'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white';");
e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" + "DataGrid1:" + "ctrl" + e.Item.ItemIndex + ":ctrl0','')");
}
public void DataGrid1_SelectedIndexChanged (Object sender, EventArgs e)
{
Label2.Text = DataGrid1.SelectedItem.Cells[3].Text;
myTextBox.Text += "Hello from SelectedIndexChanged";
}
Thanks for your help.
back but I can't seem to catch the event to do anything. My
handler never gets called. Can anyone please tell me why?
In the .aspx file:
------------------
<asp

In the code behind:
-------------------
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.ItemCreated += new DataGridItemEventHandler(this.Item_Created);
DataGrid1.SelectedIndexChanged += new EventHandler(this.DataGrid1_SelectedIndexChanged);
dbClass db = new dbClass();
DataSet ds = db.GetList();
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
void Item_Created(Object sender, DataGridItemEventArgs e)
{
e.Item.Attributes.Add ("onmouseover", "this.style.backgroundColor='beige';this.style.cursor='hand'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white';");
e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" + "DataGrid1:" + "ctrl" + e.Item.ItemIndex + ":ctrl0','')");
}
public void DataGrid1_SelectedIndexChanged (Object sender, EventArgs e)
{
Label2.Text = DataGrid1.SelectedItem.Cells[3].Text;
myTextBox.Text += "Hello from SelectedIndexChanged";
}
Thanks for your help.