Hi
I have created a gridview dynamically from scratch and added it to my aspx page. This works fine, but i have a button in the footer of on of the columns, which when clicked on makes the gridview disappear and doesn't fire the onclick event that it should. This should obviously not be the case. My question is why does the event not fire and why does the gridview vanish?
Bear in mind i have never created aa gridview in the code behind before, so excuse me if i am being dense
Code creating columns -
Dim gvTownships As New GridView
-
'COLUMNS
-
Dim tmpCategory As New TemplateField
-
tmpCategory.ItemTemplate = New cGridViewTemplate(DataControlRowType.DataRow, "Category")
-
tmpCategory.HeaderTemplate = New cGridViewTemplate(DataControlRowType.Header, "Category")
-
tmpCategory.FooterTemplate = New cGridViewTemplate(DataControlRowType.Footer, "Calculation")
-
'INFORMATION
-
gvTownships.AutoGenerateColumns = False
-
gvTownships.ID = cmbChoice.SelectedItem.Text
-
gvTownships.ShowFooter = True
-
gvTownships.CssClass = "mGrid"
-
gvTownships.RowStyle.Wrap = False
-
gvTownships.HeaderStyle.CssClass = "mgrid"
-
gvTownships.HeaderStyle.Wrap = True
-
gvTownships.FooterStyle.CssClass = "mGridtf"
-
gvTownships.AlternatingRowStyle.CssClass = "alt"
-
gvTownships.GridLines = GridLines.Both
-
-
'add columns
-
gvTownships.Columns.Add(tmpCategory)
-
-
gvTownships.DataSource = dstSuburbTowhShip
-
gvTownships.DataBind()
-
Code to add button to footer -
-
Sub InstantiateIn(ByVal container As System.Web.UI.Control) _
-
Implements ITemplate.InstantiateIn
-
-
Case DataControlRowType.Footer
-
If columnName = "Calculation" Then
-
Dim btnCalculate As New Button
-
btnCalculate.Text = "Calculate"
-
btnCalculate.CssClass = "button"
-
-
'add handler
-
AddHandler btnCalculate.Click, AddressOf btnCalculate_Clicked
-
container.Controls.Add(btnCalculate)
-
-
End If
-
-
Case Else
-
-
' Insert code to handle unexpected values.
-
-
End Select
-
-
End Sub
-
Private Sub btnCalculate_Clicked(ByVal sender As Object, ByVal e As EventArgs)
-
Try
-
Dim btnCalculate As Button = CType(sender, Button)
-
Dim gvRow As GridViewRow = CType(btnCalculate.NamingContainer, GridViewRow)
-
btnCalculate.CommandArgument = "Calculate"
-
Catch ex As Exception
-
-
End Try
-
End Sub
-
End Class
-
5 5135
When you clic the button below, the page loads again. if you dont generate the gv again, there is no reason for it to be shown.
Thanks for the prompt reply, so as i understand it the grid has to be rebuilt, thats fine, but how do i do that if the onclick event doesnt fire?
Mmm, perhaps the problem is because the page loads first, and then try to runs an event that isn't handled anymore... I'm not sure, but that could be he problem. Working with code created controls always give trouble in aspx.
Have you tried to create it in your project, and fill it with your info at runtime? just put it into a div that runs at server, with its display set to 'none' and set it to 'block' when you want to see it (or with its visible attribute).
Have you found an answer to this problem yet?
I don’t understand what the footer button, “Calculate,” does. Does it calculate the contents of the gridivew? If so, where does the calculation go?
Without the answers to those questions, the closest fix I can come up with is to use JavaScript for the “onClick” event of the button and finish the javascript code with “ return false;” so that there’s no postback.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Karl Seguin |
last post by:
i have a dynamically created user control which contains a non-dynamically
created ASP.Net button. When the button is clicked, the event is not fired.
I know that the control must be created on...
|
by: R Duke |
last post by:
I have tried everything I can think of to change the visible property
of a design time created control from a dynamically created control's
command event handler.
Here is the scenario.
I have...
|
by: Karthick Kumar |
last post by:
Hi,
I have the following code which displays all the images from a
specific folder with a Radio button in it:
Dim objFile
i = 1
For Each objFile In objFolder.Files
If (i = 1) Then...
|
by: Amelyan |
last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox,
TextBox.Text) on post back when I click submit button?
The only way I know is by traversing Response.Form enumberator;...
|
by: tfsmag |
last post by:
Hello,
I have a function that returns a dynamically created gridview. This
works fine, however it does not seem to be able to maintain state when
adding sorting or paging to the gridview. Does...
|
by: showens |
last post by:
I have a table that has rows appended dynamically, based on the item selected from a dropdownlist. The rows have a number of cells, one with a literal control using the text of the dropdownlist,...
|
by: ami |
last post by:
In my code, I need to implement x numbers of Gridviews dynamically
based on user selection. Because I am unaware of the number of
gridviews, this is done after the user enters input.
I need to...
|
by: gnewsgroup |
last post by:
I have a GridView, in which the header of one column changes depending
on the selected value of a DropDownList outside of this GridView.
I did this dynamic header through
protected void...
|
by: naasirsom |
last post by:
Dear sir,
I am using Gridview asp.net 2.0, I have a problem with Gridview Footer Template.
I have put Button, Textbox and RequiredValidator in the Footer Template and Want to validate...
|
by: Sujeetharan |
last post by:
I am writing a code for a search function. I need to search the folders for the particular file/files(only excel files/ there may be several files with the same name) & display them. I should also be...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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: 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...
| |