473,395 Members | 1,931 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,395 software developers and data experts.

Datagrids and controls - part 2

Jo
Hi,

I've tried the suggested solution but I'm still getting
the same error. It seems that once the page postback is
envoked the checkbox control is removed from the datagrid
so all my changes (ticks etc) are lost. Is there a way of
retaining the checkbox control on a postback?

Thanks,

Jo

***********************
try this

Dim mycheck As CheckBox = CType(dgWelcomePacks.Items
(i).Cells(7).Controls(1), CheckBox)

regards,
Kumar.

-----Original Message-----
Hi,

I'm doing a web application and I have a datagrid that's
linked to a dataset. For one of the columns in the
datagrid I create and add a checkbox control so that userscan easily modify the value in the dataset. I do that in
the following way:

Dim mycheck As New CheckBox()
dgWelcomePacks.Items(i).Cells(7).Controls.Add(myc heck)

I then mark the checkbox as ticked or unticked, depending
on the dataset value in the cell.
That all works fine.
Now when a user has finished with all the data in the
datagrid (ie ticking\unticking the checkboxes on differentrows) I want to be able to update the dataset with the newcheck values. I tried by running through all the rows in
the datagrid and piking up the checkbox control value:

Dim mycheck As CheckBox = CType(dgWelcomePacks.Items
(i).Cells(7).Controls(0), CheckBox)

But that gives me an error saying that there is no controlin that cell (index out of range). How can that be when I
see the checkbox in the cell on the screen? Is there
something that I'm not doing when I'm initially creating
the checkbox and adding it as a control to the cell?

Any help would be greately appreciated.

Thanks in advance,

Jo

.

Jul 19 '05 #1
1 2021
Hi Jo

Just noticed this follow up to your last post; here's what I said in reply
to that:

The key to making dynamically generated controls maintain their viewstate is
to generate them during the Page_Init event.
This occurs before the viewstate is deserialized, so provided you've created
the objects by this point the framework will do the rest for you. Any later
than this, and you've missed it! The viewstate is lost.

Hope this helps you; if you still can't get it working post some code and
I'll have a look.

Also: if you're using a designer (Visual Studio for example), you may find
it easier to add a template column to your datagrid, and drag a checkbox
into it rather than create it in code. Then all you have to do is populate
your dataset and bind the grid thus:

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
Me.OleDbDataAdapter1.Fill(Me.DataSet11)
Me.DataGrid1.DataBind()
End Sub

HTH
Regards
Joe

"Jo" <jo******@cardcall.com.au> wrote in message
news:92****************************@phx.gbl...
Hi,

I've tried the suggested solution but I'm still getting
the same error. It seems that once the page postback is
envoked the checkbox control is removed from the datagrid
so all my changes (ticks etc) are lost. Is there a way of
retaining the checkbox control on a postback?

Thanks,

Jo

***********************
try this

Dim mycheck As CheckBox = CType(dgWelcomePacks.Items
(i).Cells(7).Controls(1), CheckBox)

regards,
Kumar.

-----Original Message-----
Hi,

I'm doing a web application and I have a datagrid that's
linked to a dataset. For one of the columns in the
datagrid I create and add a checkbox control so that

users
can easily modify the value in the dataset. I do that in
the following way:

Dim mycheck As New CheckBox()
dgWelcomePacks.Items(i).Cells(7).Controls.Add(myc heck)

I then mark the checkbox as ticked or unticked, depending
on the dataset value in the cell.
That all works fine.
Now when a user has finished with all the data in the
datagrid (ie ticking\unticking the checkboxes on

different
rows) I want to be able to update the dataset with the

new
check values. I tried by running through all the rows in
the datagrid and piking up the checkbox control value:

Dim mycheck As CheckBox = CType(dgWelcomePacks.Items
(i).Cells(7).Controls(0), CheckBox)

But that gives me an error saying that there is no

control
in that cell (index out of range). How can that be when I
see the checkbox in the cell on the screen? Is there
something that I'm not doing when I'm initially creating
the checkbox and adding it as a control to the cell?

Any help would be greately appreciated.

Thanks in advance,

Jo

.

Jul 19 '05 #2

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

Similar topics

1
by: Jo | last post by:
Hi, I've tried the suggested solution but I'm still getting the same error. It seems that once the page postback is envoked the checkbox control is removed from the datagrid so all my changes...
5
by: msnews.microsoft.com | last post by:
I am new to C# (coming from java) and I am confused about how to properly work with datagrids. The application I am working on is a message based system where properties aren't changed in direct...
9
by: | last post by:
I have a web page written in asp.net that has multiple datagrids on it that would need to be exported to Excel. Each of the datagrids would be a subset of what the datagrid above it was. Thus...
4
by: ree32 | last post by:
I have a placeholder and depending on a user input(a drop downlist) when the user clicks a button I dynamically create a number of datagrids and fill them with data from a database. But the problem...
1
by: chuckdfoster | last post by:
I have 4 datagrids (dg1, dg2, dg3, and dg4) on a webpage. I know how to loop through the rows in each individual datagrid, but I need to loop through all 4. Is there a way to loop through the...
2
by: OHM | last post by:
Windows Forms Controls. Has anyone personally read and recommends a good book which includes good coverage on DataGrids as this seems to be one of the most common problem areas. Regards - OHM
0
by: Scott Meddows | last post by:
I'm having trouble scrolling some datagrids so they sync up... I have two identical datagrids on a form, filled with eh same dataset. I want a user to be able to scroll on the datasets and the...
1
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da...
4
by: mark | last post by:
(windows app not web) I have a procedure to populate a given datagrid (Datagrid1) with a dataset from an indexed data connection. It works: Globals: Dim FileName1 As String Dim DS As...
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: 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
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
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...
0
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,...

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.