473,662 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using checkbox in autogenerated datagrid

52 New Member
hi all,
I have 3 autogenerated columns and 1 template column for checkbox and im using vs 2003 in asp.net
my code is
Expand|Select|Wrap|Line Numbers
  1.         Dim myDataGridItem As DataGridItem
  2.         Dim chkSelected As New System.Web.UI.WebControls.CheckBox
  3.                 For Each myDataGridItem In dgresult.Items
  4.          chkSelected = myDataGridItem.FindControl("chkSelection")    
  5.        If chkSelected.Checked Then
  6.                 If dgresult.Items.Count Mod dgresult.PageSize = 1 And _
  7.   dgresult.CurrentPageIndex = dgresult.PageCount - 1 And _
  8.   dgresult.CurrentPageIndex <> 0 Then
  9.                     dgresult.CurrentPageIndex = dgresult.CurrentPageIndex - 1
  10.                 End If
  11.                 'update command
  12.             End If
  13.                     Next
  14.  
chkSelected returns false and the command does not execute
Jun 21 '07 #1
6 1822
kenobewan
4,871 Recognized Expert Specialist
Which event are you using?
Jun 21 '07 #2
ashasprabhu
52 New Member
Which event are you using?
im using onclick event of update button
Jun 21 '07 #3
altafhussain
4 New Member
hi all,
I have 3 autogenerated columns and 1 template column for checkbox and im using vs 2003 in asp.net
my code is
Expand|Select|Wrap|Line Numbers
  1.         Dim myDataGridItem As DataGridItem
  2.         Dim chkSelected As New System.Web.UI.WebControls.CheckBox
  3.                 For Each myDataGridItem In dgresult.Items
  4.          chkSelected = myDataGridItem.FindControl("chkSelection")    
  5.        If chkSelected.Checked Then
  6.                 If dgresult.Items.Count Mod dgresult.PageSize = 1 And _
  7.   dgresult.CurrentPageIndex = dgresult.PageCount - 1 And _
  8.   dgresult.CurrentPageIndex <> 0 Then
  9.                     dgresult.CurrentPageIndex = dgresult.CurrentPageIndex - 1
  10.                 End If
  11.                 'update command
  12.             End If
  13.                     Next
  14.  
chkSelected returns false and the command does not execute

Hi

Check whether you have written ! Ispostback ! in the page load.
Because whenever you click a button, it postbacks and the checkbox you have selected became unchecked and hence it will return false


Please check this link
http://aspalliance.com/136_DataGrid_an d_Checkboxes
Jun 21 '07 #4
ashasprabhu
52 New Member
Hi

Check whether you have written ! Ispostback ! in the page load.
Because whenever you click a button, it postbacks and the checkbox you have selected became unchecked and hence it will return false


Please check this link
http://aspalliance.com/136_DataGrid_an d_Checkboxes
hi,
thankyou very...much hussain,
actually i have copied code from the same article
My doubt is after selecting the rows only i click the button then where to store the status of the checkbox and how to use those values
Jun 21 '07 #5
altafhussain
4 New Member
hi,
thankyou very...much hussain,
actually i have copied code from the same article
My doubt is after selecting the rows only i click the button then where to store the status of the checkbox and how to use those values

Hi Prabhu

If you click "Click here to download the ASPX page", it will open a new window with this link "http://authors.aspalli ance.com/das/dg_checkbox.htm l" :)
In this link there is a method name btnSelect_OnCli ck,

you have to declare a variable inside this method and if u have to insert those checked records then you have a write a insert query inside of the for loop :)
Jun 21 '07 #6
ashasprabhu
52 New Member
hi,
i found that the pageload event was called twice which lead to the uncheck of the datagrid checkbox
thank you all [:)]
Jun 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1722
by: RA | last post by:
Hi I wonder if anyone tried this or know if it has been fixed. I am using vs .net 1.1 and have a windows form. In the form I have a DataGrid with the following format: 3 first Columns are of type text box and 5 last columns are of type checkbox(bool) I added some rows info. When the RowHeadersVisible = false here is the problem I see: When launching the application make sure to size down the window so that the
0
2156
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with these selected fields and allow user to click one or more CheckBox controls to activate this bit on the database table for a required ID. I have already added a template column to the DataGrid and I can get the
2
11674
by: Homa | last post by:
Hi, I have a Datagrid that uses as a shopping cart and have a checkbox template column in it. I can't add both OnCheckedChanged Event and onclick client script for it. I want to do two things: 1. I want the checkbox fires CheckedChanged event. I did this as
8
1835
by: Binny | last post by:
I have a DG with autogenerated columns. can i make a columns readonly like the data key column. when edititemindex is valid. Thanks
2
403
by: jax | last post by:
Hi All developers ! I have a datagrid which autogenerates columns by the sql SELECT list... The list (for some reasons) must be the same. So my question is HOW TO MOVE OUT A COLUMN FROM AUTOGENERATED DATAGRID? I would really appreciated answer with some code ! :))
0
1738
by: Luis Esteban Valencia | last post by:
Once a user clicks "add new row", a new row is created in my Datagrid. The datasource is huge so they have to scroll to the bottom of the page to edit the data in the new row. I have come across two EE solutions which use javascript to focus on the textbox in the "editcommandcolumn" mode. However, these solutions were made for non-autogenerated columns. I NEED autogenerated columns for my project. Is it possible to give focus to a...
2
6410
by: Nu2ASP.NET | last post by:
What I am trying to do is essentially 'flip' the bits, when the user clicks in the checkbox. For example, if the CheckBox appears checked, and the user un-checks it, I want the underlying data field to change from a "1" to a "0" (and vica versa). I have the bindings worked out, I just can't figure out how to do the update. Here is my source:
9
6095
by: Steve | last post by:
How I can remove an AutoGenerated column? I wnat to inlcude the primary key in the resultset for creating some custom LinkButtons, but I don't want it (the PK) displayed in the DataGrid. I tried searching the columnheader text, but found that AutoGenerated columns are members of the Columns collection. From the msdn documentation: Note: When the AutoGenerateColumns property is set to true, the columns created by the DataGrid control are...
1
6125
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.