gridview check if checkbox is checked

 I have a column with checkboxes in my gridview, I want to check each row if the checkbox was checked, if yes do something with the data of that row. How do I do that?

I added the checkboxes the following way

<asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="itemSelector" runat="server" />
                                </ItemTemplate>

</asp:TemplateField>

0
pulsmartin
7/21/2008 7:01:31 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

9 Replies
2625 Views

Similar Articles

[PageSpeed] 32

Hi,

Try using

foreach(var gvItem in myGridView.Items)
{
CheckBox chkItem = (CheckBox) gvItem.FindControl("itemSelector");
if (chkItem.Checked)
{
//Do stuff } }
aspro. 
  
Please mark your posts as answered and thank the asp gods of the forum
0
aspro
7/21/2008 7:16:12 AM

Can you give me vb code, not C please?

0
pulsmartin
7/21/2008 7:20:56 AM

u want to check the checkbox before binding the gridview or after binding the gridview ?

 

 


Jai Ganesh. J , GSD ,India

Please Mark As Answer If my reply helped you.
0
Ganesh
7/21/2008 7:23:20 AM
It has been a while since I did vb so I am not sure if it will be all correct but at least it gives you an idea.  
For Each gvRow as GridViewRow in myGridView.Rows

     dim chkItem as CheckBox = DirectCast(gvRow.FindControl("itemSelector"), CheckBox)
     if (chkItem.Checked) then
         //Do stuff
      End If
Next

 



Please mark your posts as answered and thank the asp gods of the forum
0
aspro
7/21/2008 7:30:11 AM

 

Ganesh@Nilgris:

u want to check the checkbox before binding the gridview or after binding the gridview ?

 

 

after

0
pulsmartin
7/21/2008 7:31:05 AM

write this code on button click event (event where you want to get selectd value)

 

Dim s As Integer
        For s = 0 To GridView1.Rows.Count - 1
            Dim row As GridViewRow = GridView1.Rows(s)
            Dim isChecked As Boolean = CType(row.FindControl("chkSelect"), CheckBox).Checked

            If isChecked = True Then
                SelectedVal += GridView1.Rows(s).Cells(1).Text & ","
            End If
        Next
        If Not SelectedVal Is Nothing Then
            SelectedVal = SelectedVal.Trim(",")
            Response.Write(SelectedVal.ToString())
        End If
 
Please remember to click “Mark as Answer” on the post that helps you

Jasim Akhtar
New Delhi ( INDIA )
0
miazaidi
7/21/2008 7:36:32 AM

aspro:

It has been a while since I did vb so I am not sure if it will be all correct but at least it gives you an idea.  
For Each gvRow as GridViewRow in myGridView.Rows

dim chkItem as CheckBox = DirectCast(gvRow.FindControl("itemSelector"), CheckBox)
if (chkItem.Checked) then
//Do stuff
End If
Next

 
 
This works, thank you. 
Would you mind explaining DirectCast 
0
pulsmartin
7/21/2008 7:39:45 AM

aspro:
for Each gvRow as GridViewRow in myGridView.Rows

     dim chkItem as CheckBox = DirectCast(gvRow.FindControl("itemSelector"), CheckBox)
     if (chkItem.Checked) then
         //Do stuff
      End If
Next

 
the above code is written in which event handler?
 

Jai Ganesh. J , GSD ,India

Please Mark As Answer If my reply helped you.
0
Ganesh
7/21/2008 2:45:55 PM

you can write above code onClick event or any other event where you wish to perform selected checkbox value


Please remember to click “Mark as Answer” on the post that helps you

Jasim Akhtar
New Delhi ( INDIA )
0
miazaidi
7/22/2008 3:53:39 AM
Reply:

Similar Artilces:

checking checkbox is checked or not using checkbox.checked
Hi,my checkbox is<asp:CheckBox ID="Chkcity" runat="server" Text="My own city"  OnCheckedChanged="EventHandler"/>code behind: Private Sub Chkcity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chkcity.CheckedChangedif (Chkcity ...............)end if End SubERROR    'EventHandler' is not a member of 'ASP.bpoaddjob_aspx'.    Please Mark the post as "ANSWER" if it helps you I think it should be like this:<asp:CheckBox ID="Chkcity"...

How can I check which checkbox is checked in gridview?
I have a gridview and one of the field is a template field that I inserted a checkbox (named Detailcheckbox) so that each row has a checkbox. My question is how can i click a command button an then it will verify which row is checked and store the checked row id field in an array so that I can use that array in a different page. I have try to google but all I found is written in c# and I am using VB. Thanks for help In general, use the FindControl(ControlName) method to find your checkbox by name.  The EventArgs will contain the row index.  If you find a good example in C#...

update table based on checkbox column of gridview ( if check box in gridview is checked )
 My gridview has checkbox column. Now, there is submit button on the form  . On its click event I am writing        For Each gvr As GridViewRow In GridView1.Rows            Dim chk As System.Web.UI.WebControls.CheckBox = TryCast(gvr.FindControl("CheckBox1"), CheckBox)            If (chk.Checked = True) Then  Sql = "Update [employer] set [Approved]='yes'"end if end next  But when i click the button...

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

How to check how many check boxes are checked in the gridview
I am trying to make a javascript client fucntion to restrict no more then two rows could be selectedI have following in the itemtemplate of the gridview [although it is telerik control but same technique should be applied] <radG:GridTemplateColumn UniqueName="chkCheck">                    <HeaderStyle  HorizontalAlign="Right" />                    <HeaderTempla...

Check One CheckBox To Check All CheckBoxes
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named CheckAllRows on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside within the ItemTemplate of the same TemplateColumn. This is the code (the ID of the CheckBox in the Header...

Checking the all checkboxes in Gridview control
Hi All,I am using asp.net 2.0 with c#.net.In my application i have one datalist control and in the itemtemplate of datalist control i have placed gridview control which has bound fields and template fields.and ihave checkboxes in the itemtemplate of gridview control.And i have one button outside the datalist. The datalist contains categoryid,categoryname and grid contains the coursename,courseid,duration,fee,eligibility details. Based on the category id the course  will binded up. After binding the grid if i select the checkboxes and click the button control i have to insert t...

Select all child check box by checking parent checkbox in gridview
 can any on give me the code for the Select all child check box by checking parent checkbox in gridview of only single coloum.i want to select the checkbox of one coloum only,because i have two Parent Checkbox in two Coloums .  <script language = "javascript" type = "text/javascript"> function CheckIfAll()  {    var x = 1;    for (i=0; i < document.forms[0].elements.length; i++)     {      if ((document.forms[0].elements[i].type == 'checkbox') && (document....

Check-in/Check-out
I'm having some difficulty with powerbuilder's check-in/check-out operation. When I check an object back in, the .pbl the object is being moved from is destroyed. Has anyone else experienced this and is there a fix? Cheers, Tom Thomas F. (Tom) Massey wrote: > > I'm having some difficulty with powerbuilder's check-in/check-out > operation. When I check an object back in, the .pbl the object is > being moved from is destroyed. > > Has anyone else experienced this and is there a fix? > > Cheers, > > Tom The prob...

Check In/Check out
I am using PowerBuilder 9. The undo check out is right next to the check in. This is a big problem! I so easy to select Undo check out and lose all of your changes. I lost 8 hours of work yesterday because of it. I know I should be more careful. However, there should be a "Are you sure" some where also. PLEASE FIX!!!!!!!!!!!!! -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ This isn't the tech support line, it's an end-user forum. If you want to report a bug, use CaseXpress and either open a case or report a bug ...

Check In Check Out
I have some source code that I need to modify and it was sent to me in a Registered status. Therfore, when I open any object it says " 'object name' is registered but not checked out and therefore can not be overwritten. Open anyway?" Then when I try to check it out, I get "PBNative checkout not allowed for registered objects." How can I get around this? When I look under the "Source" menu, all the items concerning registered are grayed out. TIA Option1:Copy the object(Only) to someother pbl and try . Option2:If You have any SCC Expo...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Have you looked the PB8 User's guide? Chapter 3 talks about source control. -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69ba0a.592b.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Na...

Check in
Hi all. I am migrating from PB 7.0 to PB 10.5, After migrating my first application i am trying to work on my first window but i'am not able to find out the way to CHECK it OUT. Wher do i can find "check out/check in" functions ?? TIA Mario Parietti What source control are you using? Have you configured it? Right click on your Workspace and check the source control tab to see if you've got it set up. "Mario Parietti" <mparietti@intercad.ch> wrote in message news:451283e0$1@forums-1-dub... > Hi all. > I am migrating from PB...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Better to ask this in the source control group. Lots of posts on PBNative -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69678e.7b3a.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Native. ...

Web resources about - gridview check if checkbox is checked - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 11/24/2015 10:57:08 PM