RE: Capture the Checkbox Event from DataGrid

Discussion in 'ASP .Net' started by Viny, Oct 23, 2003.

  1. Viny

    Viny Guest

    Hello,
    I am looking for the same things. Get the value of the checkbox and update it to the database. Any help will be appreciated. I dont have a update button in the datagrid. My update button is outside the datagrid.
    Thanks
    Viny

    >Hi Everyone,
    >My Datagrid has a TemplateColumn contains checkbox control and I set
    >its AutoPostback property to True. So that I can update database
    >straight after user Check or Uncheck the Checkbox.
    >
    >I don't know how to capture the event when it postback after user has
    >check/uncheck a specific checkbox, in order to update my database.
    >
    >Your help will be greatly appreiciated.
    >
    >Thanks a lot


    Message sent from http://www.aewnet.com
     
    Viny, Oct 23, 2003
    #1
    1. Advertising

  2. Hi Viny,

    Since you have multiple check boxes that may have been modified, you will
    need to iterate through all the entries in the grid. The following sample
    starts with a datagrid with one template column containing a checkbox
    control. It creates an array with four entries and binds to it to show four
    empty check boxes. Whichever check boxes you select, clicking the button
    shows the results.

    In actual usage, you will need to have one of your columns be a unique
    identifier so that you can update the correct data in your database.

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Force "flow" layout
    DataGrid1.Attributes.Remove("style")
    Button1.Attributes.Remove("style")

    If Not Page.IsPostBack Then
    Dim MyList As New ArrayList
    Dim i As Int32
    For i = 0 To 3
    MyList.Add(i)
    Next
    DataGrid1.DataSource = MyList
    DataGrid1.DataBind()
    Else
    Dim i As Int32
    For i = 0 To DataGrid1.Items.Count - 1
    Dim ck As CheckBox
    ck = DataGrid1.Items(i).Cells(0).FindControl("CheckBox1")
    Response.Write(ck.Checked & "<br>")
    'update the database here
    Next
    End If
    End Sub

    ---
    I hope this helps.

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: Viny <>
    > References: <>
    > X-Newsreader: AspNNTP 1.50 (aewnet.com)
    > Subject: RE: Capture the Checkbox Event from DataGrid
    > Mime-Version: 1.0
    > Content-Type: text/plain; charset="us-ascii"
    > Content-Transfer-Encoding: 7bit
    > Message-ID: <>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > Date: Thu, 23 Oct 2003 06:14:09 -0700
    > NNTP-Posting-Host: 63.161.67.199
    > Lines: 1
    > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
    > Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186032
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >
    > Hello,
    > I am looking for the same things. Get the value of the checkbox and

    update it to the database. Any help will be appreciated. I dont have a
    update button in the datagrid. My update button is outside the datagrid.
    > Thanks
    > Viny
    >
    > >Hi Everyone,
    > >My Datagrid has a TemplateColumn contains checkbox control and I set
    > >its AutoPostback property to True. So that I can update database
    > >straight after user Check or Uncheck the Checkbox.
    > >
    > >I don't know how to capture the event when it postback after user has
    > >check/uncheck a specific checkbox, in order to update my database.
    > >
    > >Your help will be greatly appreiciated.
    > >
    > >Thanks a lot

    >
    > Message sent from http://www.aewnet.com
    >
     
    Mike Moore [MSFT], Oct 24, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    0
    Views:
    2,620
  2. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    835
    David Wier
    Oct 6, 2006
  3. Petr Shekhtmeyster

    Cannot capture a checkbox value in the DataGrid

    Petr Shekhtmeyster, Sep 25, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    119
    Petr Shekhtmeyster
    Sep 25, 2003
  4. news.microsoft.com

    Capture CheckBox Click Event

    news.microsoft.com, Dec 13, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    279
    Marc Rivait
    Dec 16, 2003
  5. Joey Pang
    Replies:
    4
    Views:
    528
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page