473,288 Members | 1,710 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,288 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 2017
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.