Checkbox in a Datagrid with an CheckedChanged event?

R

REB

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
 
R

REB

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
 
A

Alvin Bruney [MVP]

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
 
R

REB

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top