473,378 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Gridview / autopostback problem

Hi

I have problems with autopostback and the gridview control. Please
continue reading.

The code below turns a row red when a tickbox is ticked in
edititemtemplate. Note autopostback on the tickbox is enabled and the
code works perfectly.

-------------------------------------------------------------------------------------------------------------------
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e
As System.EventArgs)

Dim checkbox As CheckBox = CType(sender, CheckBox)
Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)

If checkbox.Checked = True Then
row.BackColor = Drawing.Color.Red

'mygridview.Columns(0).Visible = False

end if
end sub
-------------------------------------------------------------------------------------------------------------------

However if I uncomment:
mygridview.Columns(0).Visible = False

....then the behaviour changes.

The first time I click the tickbox the column hides and the tickbox
doesn't get ticked like it should. The second time I click the
textbox the row turns red (column remains hidden).

I need the column hidden and the row colour to change on one
autopostback, not two. How can I achieve this?

Many thanks

Alex

Mar 31 '06 #1
1 7705
Alex,

I haven't been able to replicate the behaviour you describe. But I do have a
small example that works exactly the way you describe:

<asp:GridView ID="MyGridView" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="MyCheckBox" runat="server"
AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Not Page.IsPostBack Then
Dim DataTable As New Data.DataTable
DataTable.Columns.Add("Column1", GetType(String))
DataTable.Columns.Add("Column2", GetType(String))
Dim DataRow As Data.DataRow = DataTable.NewRow
DataRow.Item(0) = "Test1"
DataRow.Item(1) = "Test2"
DataTable.Rows.Add(DataRow)
MyGridView.DataSource = DataTable
MyGridView.DataBind()
End If
End Sub

Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim checkbox As CheckBox = CType(sender, CheckBox)
Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)
If checkbox.Checked = True Then
row.BackColor = Drawing.Color.Red
mygridview.Columns(0).Visible = False
End If
End Sub
Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
<po******@alexshirley.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Hi

I have problems with autopostback and the gridview control. Please
continue reading.

The code below turns a row red when a tickbox is ticked in
edititemtemplate. Note autopostback on the tickbox is enabled and the
code works perfectly.

-------------------------------------------------------------------------------------------------------------------
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e
As System.EventArgs)

Dim checkbox As CheckBox = CType(sender, CheckBox)
Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)

If checkbox.Checked = True Then
row.BackColor = Drawing.Color.Red

'mygridview.Columns(0).Visible = False

end if
end sub
-------------------------------------------------------------------------------------------------------------------

However if I uncomment:
mygridview.Columns(0).Visible = False

...then the behaviour changes.

The first time I click the tickbox the column hides and the tickbox
doesn't get ticked like it should. The second time I click the
textbox the row turns red (column remains hidden).

I need the column hidden and the row colour to change on one
autopostback, not two. How can I achieve this?

Many thanks

Alex

Mar 31 '06 #2

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

Similar topics

6
by: tfsmag | last post by:
I have a Grid that I've set up to have two of the fields use dropdownlists while in edit mode. Now I can bind the data to the dropdownlists just fine. My problem is that the second dropdown depends...
0
by: rmccinc | last post by:
I have a dropdownlist in a datagrid and it has autopostback set to true. I need to get the new value of that dropdown to fill a textbox in the same datagrid row. I have set the databind event on...
3
by: tarscher | last post by:
Hi all, I have a gridview populated with data coming from a dataset (created via the wizard). The data shown in the gridview is dependent on the the choice of a control (dropdown with...
3
by: Jon Paal | last post by:
this text keeps showing up in my gridview dropdownlist "System.Data.DataRowView" How do I prevent this problem ?
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
4
by: =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post by:
I setup a simple gridview as a utility just to do some updates, nothing fancy just wanted easy UI to make updates. When I select ‘Edit’, I get the fields I want to edit. I edit them and click...
2
by: wildman | last post by:
RE: Gridview textbox has data check without postback.. javascript? I have a gridview with a textbox. I can set the textbox to autopostback and check for a value in a prerender event to decide if...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview with several template columns and a few command button columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column 4 is a text box, followed by command button...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
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...

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.