473,756 Members | 3,973 Online
Bytes | Software Development & Data Engineering Community
+ 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="dgdSearchRe sults" runat="server"
OnItemCommand=" dgdSearchResult s_ItemCommand">
<HeaderStyle CssClass="Title "></HeaderStyle>
</asp:datagrid>

In my code-behind I have this:

protected void dgdSearchResult s_ItemCommand(o bject sender,
DataGridCommand EventArgs e)
{
string strFunctionName = "dgdSearchResul ts_ItemCommand" ;
long lngAuthorID = 0;
CISTable.User oUser;
if (e.CommandName == "Select")
{
//An author was selected to be added to the Author hidden element
this.hidAuthorI D.Value = e.Item.ItemInde x;
}
}

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

btn.ButtonType = ButtonColumnTyp e.PushButton;
btn.HeaderText = "Select";
btn.CommandName = "Select";
btn.DataTextFie ld = "AuthorID"
btn.Text = "Select";
this.dgdSearchR esults.Columns. Add(btn);
btn = null;

That didn't work so I added this to the InitializeCompo nent() method:
this.dgdSearchR esults.ItemComm and += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler(this.d gdSearchResults _
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 dgdSearchResult s_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 1102
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******** *******@tk2msft ngp13.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*******@hotm ail.IHATESpam.c om> wrote in message
news:us******** ******@TK2MSFTN GP09.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******** *******@tk2msft ngp13.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
2126
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 Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
4
5178
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 Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
4
2137
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 Delete button on the end of each row. I am unable to gain access to the event when the button is clicked. I don't fully understand how the click gets connected to the C# code,
9
2727
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
0
2702
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(); } private void CreateGridView() {
0
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9708
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.