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:DataGrid id="DataGrid1" runat="server" Width="400px"OnSelectedIndexChanged="DataGrid1_Sel ectedIndexChanged">
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.cur sor='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. 5 3078
What happens if you comment out the "e.Item.Attributes.Add("onclick",
"javascript :__doPostBack('" + "DataGrid1:" + "ctrl" + e.Item.ItemIndex +
":ctrl0','')");" ??
"Bruce W.1" <bw@noDirectEmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl... 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:DataGrid id="DataGrid1" runat="server"
Width="400px"OnSelectedIndexChanged="DataGrid1_Sel ectedIndexChanged">
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.cur sor='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.
Pat wrote: What happens if you comment out the "e.Item.Attributes.Add("onclick", "javascript:__doPostBack('" + "DataGrid1:" + "ctrl" + e.Item.ItemIndex + ":ctrl0','')");" ??
================================================== ======
It does not post back (when clicking in the DataGrid) when this line is
commented out.
Two suggestions....
1. In your .aspx file, try adding a space between "400px" and
OnSelectedIndexChanged. It might matter it might not. Dumber things
have happened to me.
2. Try removing the OnSelectedIndexChanged declaration in the .aspx
You are already setting up the event handler in the Page_Load. It
might be messing it up.
Good luck,
Neil
"Bruce W.1" <bw@noDirectEmail.com> wrote in message news:<#s*************@tk2msftngp13.phx.gbl>... 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:DataGrid id="DataGrid1" runat="server" Width="400px"OnSelectedIndexChanged="DataGrid1_Sel ectedIndexChanged">
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.cur sor='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.
nfedin wrote: Two suggestions....
1. In your .aspx file, try adding a space between "400px" and OnSelectedIndexChanged. It might matter it might not. Dumber things have happened to me.
2. Try removing the OnSelectedIndexChanged declaration in the .aspx You are already setting up the event handler in the Page_Load. It might be messing it up.
Good luck,
Neil
================================================== ====
Good suggestions, but they did not work.
Is there a way to look at the event that caused the postback?
I should add that this is based on this article: http://www.dotnetbips.com/displayarticle.aspx?id=205
I loaded the source code for this article and it works fine. You click
on a name in the datagrid and it puts the name in a label.
The only big difference I see in the code (other than being VB instead
of C#) is this line:
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
I'm not sure why the label would be an event handler. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bob Rosen |
last post by:
The description given in "Customizing Items Dynamically in the DataList or
DataGrid Web Server Control"
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbCode/...
|
by: Supa Hoopsa |
last post by:
I have a standard combo box in a datagrid (DataGridEnableComboBoxColumn) and
I want to catch the SelectionChangeCommitted event.
Does anyone know how to do this?
|
by: xrow |
last post by:
Hello
I have a simple webservice / c# application that receives data from server and prints the data in the asp:datagrid control
I have problem when sorting data in datagrid
I have created...
|
by: mhw |
last post by:
How to catch the enter key of TestBox that DataGrid hits ?
|
by: needin4mation |
last post by:
I'm writing c# asp.net. I have a dataset loading when the page loads
and it has an itemdatabound event.
When there is an error in the itemdatabound event I get the catch in
the calling...
|
by: vinayak |
last post by:
Hi
I am displaying data in Datagrid in ASP.NET with
Edit/Update functionality for each row. On the same page I
have 2 Button controls which submits the request to
server. These button controls...
|
by: Teep |
last post by:
New to .net framework and in a bit of a crunch, I have found myself
trying to figure out things from online examples.
I have a datagrid which displays records from a SQL table, I also have
two...
|
by: Gene Hubert |
last post by:
I'm trying to catch the KeyUp event in textbox of a DataGrid. I'm
picking up the keydown and keypress events ok, but not keyup. Can
anyone see what is wrong with this code. I been fighting with...
|
by: Just Me |
last post by:
Given a button name Btn_5 and Index=5
I want to do something like
dim zz as string = Btn_??Index??.Text
or given an array of buttons, do:
|
by: mttc |
last post by:
I read articles that suggest preventing delete by throwing Exception from
RowDeleting Event.
I not understand where I can catch this Error?
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |