Using SQL 2000 and VS2005
I have a GridView control which has 12 dynamically created buttons in the header row created as follows: -
-
Protected Sub gvSCTPivot_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSCTPivot.RowDataBound
-
'Create the 12 buttons
-
For Index = 1 To 12
-
If e.Row.RowType = DataControlRowType.Header Then
-
Dim NewBtn As Button = New Button
-
NewBtn.Text = GetFinMonth(Index)
-
NewBtn.CausesValidation = False
-
NewBtn.ID = Index
-
NewBtn.Width = 35
-
NewBtn.Font.Size = 11
-
AddHandler NewBtn.Click, AddressOf btn_Clicked
-
e.Row.Cells(Index).Controls.Add(NewBtn)
-
-
End If
-
Next Index
-
-
End Sub
-
-
Sub btn_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
-
Session("MonthNum") = CInt(CType(sender, Button).ID)
-
Session("MonthName") = GetFinMonth(Session("MonthNum"))
-
If Session("MonthNum") < 4 Then
-
Session("Year") = Session("FinYear") - 1
-
Else
-
Session("Year") = Session("FinYear")
-
End If
-
If Me.gvSCTPivot.Rows(0).Cells(Session("MonthNum")).Text.ToString = " " Then
-
Response.Redirect("SC+TAdd.aspx")
-
Else
-
Response.Redirect("SC+TEdit.aspx")
-
End If
-
-
End Sub
-
The GridView EnableViewState property is also set to False
One of 2 DataSource controls are bound at runtime depending on whether the underlying data exists or not. The buttons fire OK with the first DataSource control. But they do not work with the second DataSource control.
The first DataSource control code where the buttons DO work is as follows: -
SELECT TitleId, Name,
-
Sum(Case when FinMonth = 1 then Amount else NULL end) as Apr,
-
Sum(Case when FinMonth = 2 then Amount else NULL end) as May,
-
Sum(Case when FinMonth = 3 then Amount else NULL end) as Jun,
-
Sum(Case when FinMonth = 4 then Amount else NULL end) as Jul,
-
Sum(Case when FinMonth = 5 then Amount else NULL end) as Aug,
-
Sum(Case when FinMonth = 6 then Amount else NULL end) as Sep,
-
Sum(Case when FinMonth = 7 then Amount else NULL end) as Oct,
-
Sum(Case when FinMonth = 8 then Amount else NULL end) as Nov,
-
Sum(Case when FinMonth = 9 then Amount else NULL end) as Dec,
-
Sum(Case when FinMonth = 10 then Amount else NULL end) as Jan,
-
Sum(Case when FinMonth = 11 then Amount else NULL end) as Feb,
-
Sum(Case when FinMonth = 12 then Amount else NULL end) as Mar,
-
Sum(Amount) as Total,
-
Round(AVG(Amount),1) as Mean
-
from SCTPivot
-
left join SCTTitle
-
on SCTPivot.Title = SCTTitle.TitleId
-
Where FinYear = @FinYear
-
Group by TitleId, Name
-
Order by TitleId
-
The second DataSource control code where the buttons DO NOT work is as follows: -
Select TitleId, Name,'' as Apr, '' as May, '' as Jun, '' as Jul, '' as Aug, '' as Sep, '' as Oct, '' as Nov, '' as Dec, '' as Jan, '' as Feb, '' as Mar, '' as Total, '' as Mean
-
From SCTTitle
-
-
Union
-
-
SELECT TitleId, Name,
-
Sum(Case when FinMonth = 1 then Amount else NULL end) as Apr,
-
Sum(Case when FinMonth = 2 then Amount else NULL end) as May,
-
Sum(Case when FinMonth = 3 then Amount else NULL end) as Jun,
-
Sum(Case when FinMonth = 4 then Amount else NULL end) as Jul,
-
Sum(Case when FinMonth = 5 then Amount else NULL end) as Aug,
-
Sum(Case when FinMonth = 6 then Amount else NULL end) as Sep,
-
Sum(Case when FinMonth = 7 then Amount else NULL end) as Oct,
-
Sum(Case when FinMonth = 8 then Amount else NULL end) as Nov,
-
Sum(Case when FinMonth = 9 then Amount else NULL end) as Dec,
-
Sum(Case when FinMonth = 10 then Amount else NULL end) as Jan,
-
Sum(Case when FinMonth = 11 then Amount else NULL end) as Feb,
-
Sum(Case when FinMonth = 12 then Amount else NULL end) as Mar,
-
Sum(Amount) as Total,
-
Round(AVG(Amount),1) as Mean
-
from SCTPivot
-
left join SCTTitle
-
on SCTPivot.Title = SCTTitle.TitleId
-
Where FinYear = 2010
-
Group by TitleId, Name
-
Order by TitleId
-
Both DataSource controls display data and the buttons in the GridView. One Datasource does work with the buttons and the other does not. Please can you help?
Thanks
Kind Regards
mike
1 1889
Where are you doing your DataBind in the life cycle of the page?
Have you considered placing the buttons in the template for the GridView so that you can specify the method for the button click event instead of doing this in Code Behind?
Have you considered configuring your GridView to use the RowCommand Event to handle the button click event?
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
Any nice examples utilizing dynamic buttons. I'd like to see a tutorial and
a working example.
Dave
|
by: MikeY |
last post by:
Hi Everyone,
Does anyone know where I can get my hands on a sample with source code of a
simple dynamic button control in C# Windows form. I am looking for a sample
that uses a class library...
|
by: andrei |
last post by:
Hi Group,
I have an aspx form with a variable number of buttons added dynamically,
with id's like b01, b02, b03...
Whenever I click one of these buttons, the form is posted back.
I need to...
|
by: Tim_Mac |
last post by:
hi,
i'm new to .net 2.0, and am just starting to get to grips with the
gridview.
my page has autoEventWireUp set to true, which i gather is supposed to
figure out which handlers to invoke when...
|
by: AG |
last post by:
I have a gridview that I bind to a List(of Type) at runtime.
Not using a datasource control.
The gridview has a template column with an imagebutton whose commandname is
set to 'Delete'.
The...
|
by: beton3000 |
last post by:
Hello!
I'm building a GridView using code to add template fields, because
there is a random number of columns in result set from database. I'm
using a class with ITemplate interface for defining...
|
by: lilOlMe |
last post by:
Hi there!
I have generated a GridView that looks something like:
SportName| CompanyNameX |CompanyNameY |CompanyNameZ
Hockey.....| Shipping------------ |Accounting-------- |Shipping------------...
|
by: jimmysjams |
last post by:
I'm modifying someone else's code and I have hit a snag. I don't
want
to rewrite what's already there but I might have to.
I have a gridview, in the gridview is a set number of columns that...
|
by: spamguy |
last post by:
I am working porting ugly .NET 1.1 DataGrids to 2.0 GridViews. The GridView fills correctly via SqlDataSource. When I click Edit -> -> Update, the page refreshes but the update command clearly never...
|
by: Frinavale |
last post by:
I've created a ASP.NET control that displays a "book" of schedules.
It dynamically displays scheduling times and allows the user to page through the schedules. It also lets the user edit the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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,...
|
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: 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...
|
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...
| |