473,463 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datagrid event problem

I still consider myself to be a novice with ASP.NET, and going through the
samples in my books is not helping me spot the problem. I very often find
my answer after I've posted so maybe it will happen again? :-)

I'm having trouble getting an ButtonColumn click event to fire. I set a
break point in the event method and it doesn't break.

here's my Datagrid in the ASPX file:

<asp:datagrid id="dgdSearchResults" runat="server"
OnItemCommand="dgdSearchResults_ItemCommand">
<HeaderStyle CssClass="Title"></HeaderStyle>
</asp:datagrid>

In my code-behind I have this:

protected void dgdSearchResults_ItemCommand(object sender,
DataGridCommandEventArgs e)
{
string strFunctionName = "dgdSearchResults_ItemCommand";
long lngAuthorID = 0;
CISTable.User oUser;
if (e.CommandName == "Select")
{
//An author was selected to be added to the Author hidden element
this.hidAuthorID.Value = e.Item.ItemIndex;
}
}

At design time I add a ButtonColumn to the Datagrid before I bind my
DataSet:

btn.ButtonType = ButtonColumnType.PushButton;
btn.HeaderText = "Select";
btn.CommandName = "Select";
btn.DataTextField = "AuthorID"
btn.Text = "Select";
this.dgdSearchResults.Columns.Add(btn);
btn = null;

That didn't work so I added this to the InitializeComponent() method:
this.dgdSearchResults.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgdSearchResults_
ItemCommand);

Still no luck. All the other buttons, not in a Datagrid are firing the
_click events and running the methods properly, but thie button in the grid
will not. Everything appears correctly in the web browser, but when the
Button is clicked, the dgdSearchResults_ItemCommand is never entered and the
code is not executed. It only goes through Page_Load and not through the
events method.

Can anybody tell me what I'm missing before I go insane???

Andrea
PS: I ran a few searches in the KB articles, but found nothing that would
help.
Nov 18 '05 #1
3 1091
Hi,

Ensure that your dynamic add button is added every time the page is
loading (including postbacks). If you wont create dynamic add controls
they simply don't exist and cant raise any events...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
I separated out the code into a test page and the command event fired like
it was supposed to. So I stuck the working code into a User Control to see
if if would still work. (My main code is in a user control and I found a
post where someone thinks that the events don't fire in User Controls.) The
code still works, one theory blown.... So I start adding peices of code
until it broke. When I moved the .DataBind() to the Search button click
event, the DataGrids button quit working. If I leave the Bind in the
Page_Load routine, then the events work. If I don't bind the grid on the
first pass, the events fail to work.

So, my new question is... If I have to bind a datasource to the grid on
every single pass, even when I don't know what my data is going to be, how
do I bind a blank datasource to the grid? Anyone have any ideas?

Andrea
"Natty Gur" <na***@dao2com.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

Ensure that your dynamic add button is added every time the page is
loading (including postbacks). If you wont create dynamic add controls
they simply don't exist and cant raise any events...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3
Nevermind... This is not the case after all. Looks like just the creation
of the columns has to be in the page_load every time AND the binding has to
take place in the Page_Load. I had it placed in a button click event before
and that doesn't seem to allow the events to fire.

Thanks for your ideas!

Andrea
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
I separated out the code into a test page and the command event fired like
it was supposed to. So I stuck the working code into a User Control to see if if would still work. (My main code is in a user control and I found a
post where someone thinks that the events don't fire in User Controls.) The code still works, one theory blown.... So I start adding peices of code
until it broke. When I moved the .DataBind() to the Search button click
event, the DataGrids button quit working. If I leave the Bind in the
Page_Load routine, then the events work. If I don't bind the grid on the
first pass, the events fail to work.

So, my new question is... If I have to bind a datasource to the grid on
every single pass, even when I don't know what my data is going to be, how
do I bind a blank datasource to the grid? Anyone have any ideas?

Andrea
"Natty Gur" <na***@dao2com.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

Ensure that your dynamic add button is added every time the page is
loading (including postbacks). If you wont create dynamic add controls
they simply don't exist and cant raise any events...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: edurazee | last post by:
I am able to create BoundFields and Footer-rows dynamically like this in my GridView: protected void Page_Load(object sender, EventArgs e) { CreateGridView(); ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
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...
1
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.