Checkbox in a Datagrid with an CheckedChanged event?

Discussion in 'ASP .Net Datagrid Control' started by REB, Mar 1, 2004.

  1. REB

    REB Guest

    I am trying to create a CheckChanged event for a check box in a datagrid so
    that when a user checks or unchecks the box a update is done for the record.

    Can anyone point my in the right direction?

    Thanks,
    REB
    REB, Mar 1, 2004
    #1
    1. Advertising

  2. Your post went unanswered. Have you resolved this issue?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "REB" <> wrote in message
    news:ujkHEE9$...
    > I am trying to create a CheckChanged event for a check box in a datagrid

    so
    > that when a user checks or unchecks the box a update is done for the

    record.
    >
    > Can anyone point my in the right direction?
    >
    > Thanks,
    > REB
    >
    >
    Alvin Bruney [MVP], Mar 2, 2004
    #2
    1. Advertising

  3. REB

    REB Guest

    No I have not yet figured it out. There must be a way to manually create a
    checkedchanged event for the checkboxes in the grid, but I do not know how.

    Still searching,
    REB


    "REB" <> wrote in message
    news:ujkHEE9$...
    > I am trying to create a CheckChanged event for a check box in a datagrid

    so
    > that when a user checks or unchecks the box a update is done for the

    record.
    >
    > Can anyone point my in the right direction?
    >
    > Thanks,
    > REB
    >
    >
    REB, Mar 2, 2004
    #3
  4. It really depends on how you added the control to the grid. If it is
    embedded in the column (it likely is) it will fire off the itemcommand
    automatically. So you can place your code in there. Use the sender argument
    or the commandname property to determine if it came from the checkbox or
    somewhere else.

    Otherwise, if you created the checkbox dynamically, you will need to
    manually wire it up to an event like so
    this.CheckBox1.Checked += new System.EventHandler(some_function_goes_here);

    You would then place the appropriate code in some_function_goes_here
    function


    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "REB" <> wrote in message
    news:...
    > No I have not yet figured it out. There must be a way to manually create

    a
    > checkedchanged event for the checkboxes in the grid, but I do not know

    how.
    >
    > Still searching,
    > REB
    >
    >
    > "REB" <> wrote in message
    > news:ujkHEE9$...
    > > I am trying to create a CheckChanged event for a check box in a datagrid

    > so
    > > that when a user checks or unchecks the box a update is done for the

    > record.
    > >
    > > Can anyone point my in the right direction?
    > >
    > > Thanks,
    > > REB
    > >
    > >

    >
    >
    Alvin Bruney [MVP], Mar 2, 2004
    #4
  5. REB

    REB Guest

    The control is embedded, but it does not seem to automatically fire off the
    itemcommand for the datagrid. I put a simple Response.Write in the
    itemcommand function for the datagrid and it did not work.

    My datagrid is simple and only has 4 columns (one of which is the key field
    and is invisible) I included the html for the datagrid at the end of this
    message, but without formatiing is really hard to read here in the newsgroup
    if that helps.

    The name of my check box in the templated column is checkbox1 how do I use
    the sender argument to tell if it has been clicked?

    Thanks,
    REB

    <asp:textbox id="txtViolationType" runat="server"
    Width="236px"></asp:textbox><asp:button id="btnSaveViolation" runat="server"
    Text="Save Violation"
    CausesValidation="False"></asp:button></FONT></STRONG><STRONG><FONT
    size="2"><asp:datagrid id=dgTrafficViolations runat="server"
    BorderStyle="None" BackColor="White" AutoGenerateColumns="False"
    DataMember="Table" DataKeyField="DriverViolationID" DataSource="<%#
    dsViolations1 %>" BorderColor="#CC9966" BorderWidth="1px" CellPadding="4">
    <SelectedItemStyle Font-Bold="True" ForeColor="#663399"
    BackColor="#FFCC66"></SelectedItemStyle>
    <ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
    BackColor="#990000"></HeaderStyle>
    <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
    <Columns>
    <asp:BoundColumn Visible="False" DataField="DriverViolationID"
    SortExpression="DriverViolationID"
    HeaderText="DriverViolationID">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    </asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Violations Notice">
    <ItemTemplate>
    <asp:CheckBox id=CheckBox1 runat="server" AutoPostBack="True"
    Checked='<%# DataBinder.Eval(Container, "DataItem.DriverTraffic Violations
    Notice") %>'>
    </asp:CheckBox>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox id=TextBox1 runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.DriverTraffic Violations Notice") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="DriverTrafficViolationsNoticeDate"
    SortExpression="DriverTrafficViolationsNoticeDate"
    HeaderText="Notice Date"
    DataFormatString="{0:d}"></asp:BoundColumn>
    <asp:BoundColumn DataField="DriverViolationType"
    SortExpression="DriverViolationType"
    HeaderText="Violation"></asp:BoundColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Center" ForeColor="#330099"
    BackColor="#FFFFCC"></PagerStyle>
    </asp:datagrid>
    REB, Mar 3, 2004
    #5
    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. Greg Hurlman
    Replies:
    5
    Views:
    1,937
    Greg Hurlman
    Dec 4, 2003
  2. Chris Jackson
    Replies:
    0
    Views:
    519
    Chris Jackson
    Dec 9, 2003
  3. Jump Off!

    CheckedChanged Event doesn't work?

    Jump Off!, Jul 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    8,238
  4. Replies:
    2
    Views:
    8,601
    tdavisjr
    Oct 17, 2005
  5. marian

    dyanmic checkbox/itemplate/checkedchanged uncheck issue

    marian, Aug 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    172
    marian
    Aug 8, 2005
Loading...

Share This Page