ASP.Net Button Command Not Firing (C#)

Associate
Joined
25 Feb 2007
Posts
905
Location
Midlands
I have an initial summary GridView which has a datasource created from a SQL database. The rows in this GridView can be clicked which passes parameters to the URL.

As this initiates a page load, I have an if statement to check for a certain querystring and modifying the datasource based on the other parameters passed, so I'm using the same GridView with a sort of 'drilldown' feature.

After the drilldown, I want to add an additional column with a button, which I've managed to do. I need this buttoon to update a field in the database when clicked, so I've set the button.CommandName property to a method which does this.

Everything works fine, except the method doesn't fire when I click the button!

From some research, it seems that as the clicking of the button triggers a postback, the event is caught??

Can anyone help?

Thanks :D
 
Associate
Joined
13 Aug 2008
Posts
221
Any reason for not using Ajax to change the data? Means a richer user experience and this shouldn't be a problem anymore.

I understand its not what you asked, but if there is a reason not to use Ajax it may change possible work arounds.
 
Associate
Joined
25 Dec 2005
Posts
58
Location
Nottingham
What are you trying to achieve? have you placed the buttons within your GridView template?

http://msdn.microsoft.com/en-us/library/bb907626%28v=vs.100%29.aspx

if you wanted to send me your code i'm happy to take a quick look...

Any reason for not using Ajax to change the data? Means a richer user experience and this shouldn't be a problem anymore.

I understand its not what you asked, but if there is a reason not to use Ajax it may change possible work arounds.

I second that question.. why are you using asp.net gridviews? why not use pure html, ajax, jquery templates, json to do the job, it doesn't take much more work, you have much more control over the outcome, and the user experiance is greatly improved.
 
Associate
OP
Joined
25 Feb 2007
Posts
905
Location
Midlands
To be honest I'm quite new to this(!) A GridView was the only way I could see to display data from a database in tabular form. Can you provide any examples of how I'd use AJAX to do this? I'm only updating one field in my database though - it's more of a 'view only' app and the user never sees the field being updated, is Ajax still the way to go?

Yes I have a button within my GridView, and can you expand on what you mean by validation controls durbs?

Basically what I'm trying to implement is a way for the user to hide a row that they've already 'dealt' with. So the button updates a date field in the database with a 'today + 1' value. The query which populates the GridView then ignores all rows with dates greater than today.

Thanks for the replies guys, much appreciated!
 
Associate
OP
Joined
25 Feb 2007
Posts
905
Location
Midlands
OK, I've resolved my issue - like an idiot, I forgot to add the OnRowCommand attrbute to the GridView markup! Always the simplest of things!

I'm still interested in making my application better though, so the above still applies! :D
 
Back
Top Bottom