473,715 Members | 6,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp checkbox checking for OnCheckedChange d value

Hi everyone,

I am reading and displaying data rows from my database where the first
column contains the Status checkbox. I like to enable my users to change
the status of individual rows by checking and unchecking the checkbox
column. I like to update the status in the database for the column where
the status was changed.

This is what I'm doing so far

<asp:datagrid id="MyDataGrid " runat="server" CellPadding="2"
AutoGenerateCol umns="false" HeaderStyle-CssClass="maint ableheader"
Width="95%">
<Columns>
<asp:BoundColum n DataField="BID" ReadOnly="True"
Visible="False" ></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Act ive" Visible="True"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:CheckBox ID="Status" Runat="server" Checked='<%#
FormatStatus(Da taBinder.Eval(C ontainer.DataIt em, "Status")) %>'
AutoPostBack=Tr ue OnCheckedChange d="UpdateCheckb oxStatus">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
....etc.

and in my .cs page

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
Response.Write ("You click the row...")...
}

How can I find out which row was clicked? Please let me know if there is a
better way to do this.

Thank you
Maz
Nov 18 '05 #1
2 6632
Hi,

you get to the CheckBox's parent DataGridItem by utilizing the hierarchical
idea of Controls collection, meaning that get it via your Control's Parent
property.

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
//Written into several lines to clarify, you could go with one line

//Current checkbox
CheckBox box=(CheckBox)s ender;

//The TableCell the control is in
TableCell cell=(TableCell )box.Parent;

//The DataGridItem the cell belongs to
DataGridItem dgItem=(DataGri dItem)cell.Pare nt;
}

With that DataGridItem you get for example ItemIndex of the DataGridItem you
are into. It is the same would be e.Item in ItemCommand,Ite mDataBound or
ItemCreated. And you can then again get the PK of the current row and so on
via DataKeys collection.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Maziar Aflatoun" <ma***@rogers.c om> wrote in message
news:27******** *************@n ews01.bloor.is. net.cable.roger s.com...
Hi everyone,

I am reading and displaying data rows from my database where the first
column contains the Status checkbox. I like to enable my users to change
the status of individual rows by checking and unchecking the checkbox
column. I like to update the status in the database for the column where
the status was changed.

This is what I'm doing so far

<asp:datagrid id="MyDataGrid " runat="server" CellPadding="2"
AutoGenerateCol umns="false" HeaderStyle-CssClass="maint ableheader"
Width="95%">
<Columns>
<asp:BoundColum n DataField="BID" ReadOnly="True"
Visible="False" ></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Act ive" Visible="True"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:CheckBox ID="Status" Runat="server" Checked='<%#
FormatStatus(Da taBinder.Eval(C ontainer.DataIt em, "Status")) %>'
AutoPostBack=Tr ue OnCheckedChange d="UpdateCheckb oxStatus">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
...etc.

and in my .cs page

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
Response.Write ("You click the row...")...
}

How can I find out which row was clicked? Please let me know if there is a
better way to do this.

Thank you
Maz

Nov 18 '05 #2
Teemu gave a great answer. For some more sample code see my article
here:

http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com

On Sun, 05 Sep 2004 06:12:14 GMT, "Maziar Aflatoun" <ma***@rogers.c om>
wrote:
Hi everyone,

I am reading and displaying data rows from my database where the first
column contains the Status checkbox. I like to enable my users to change
the status of individual rows by checking and unchecking the checkbox
column. I like to update the status in the database for the column where
the status was changed.

This is what I'm doing so far

<asp:datagri d id="MyDataGrid " runat="server" CellPadding="2"
AutoGenerateCo lumns="false" HeaderStyle-CssClass="maint ableheader"
Width="95%">
<Columns>
<asp:BoundColum n DataField="BID" ReadOnly="True"
Visible="False "></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Act ive" Visible="True"
ItemStyle-HorizontalAlign ="Center">
<ItemTemplate >
<asp:CheckBox ID="Status" Runat="server" Checked='<%#
FormatStatus(D ataBinder.Eval( Container.DataI tem, "Status")) %>'
AutoPostBack=T rue OnCheckedChange d="UpdateCheckb oxStatus">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
...etc.

and in my .cs page

public void UpdateCheckboxS tatus(object sender, System.EventArg s e)
{
Response.Write ("You click the row...")...
}

How can I find out which row was clicked? Please let me know if there is a
better way to do this.

Thank you
Maz


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1600
by: Paul Fitzpatrick | last post by:
Hi, This is a real beginner question! I have a form with a few types of products. I need to limit the number that the user puts in for quantity of each product - I have to keep it below 2. So onsubmit of the form it checks that the values are less than 2. SO far I have -
1
2306
by: Netmonster | last post by:
Hello, Can someone tell me what I'm doing wrong? I am trying to check the value of a hashtable and I know the value will be true or false. The data is coming from a sql db column with bit as its datatype. If the DB value is 0 the hashtable in a vs.net debug shows the value of {false} Here is a piece of code. htData is a return from a sql query. I have tried both
1
2074
by: Paul | last post by:
Hi I have a checkbox which I am disabling in clientside code. On postback, when I try to read the checked value of the disabled checkbox the checkbox property always returns false, even if the checkbox is checked. Surely it should still be true. Any ideas?
2
1770
by: Andy G | last post by:
How can I check this for null? dsPrsn.Tables(0).Rows(0)("WORK_STATE") I tried If IsDbNull(dsPrsn.Tables(0).Rows(0)("WORK_STATE")) Then it seems not too work. I am attempting to check this field in my data set to see if it is null or not. If it is null I want to set my drop down list to a certain value (where I'm using dropdown.SelectedValue = ). If it is not null I want to set the drop down to the dataset value. Here is what the...
0
1352
by: Paul | last post by:
Hello, I have a datagridview with a checkbox in a column, and I want to detect when the user change the value of the checkbox in the event CheckedChanged, but I only detect that the value is changed when the focus is in another column. An idea? Thanks
1
1412
by: Jim in Arizona | last post by:
Using VB .. Is there a way to loop through all drop down lists on a web form checking for a specific value (ddlDropDown.SelectedValue) and then, based on that value, cause a specific label to go visible or not? Thanks, Jim
1
2862
Fary4u
by: Fary4u | last post by:
Hi is any body know where is actual problem is coz it's look me some problem ? to insert value into the MS ACCESS DATABASE after the value is true form html <input type="checkbox" name="1" value="1"> <input type="checkbox" name="2" value="2">
0
777
by: jeenajos | last post by:
Hi all, Im doing a website project.Im stuck in a problem. I have a set of values in database. While entering a value in a textbox it should check whether that value is present in the database or not. and if that value is there, we should check whether its flag value is true or false.If its false we should accept that value from textbox and make the flag as true.If its value is true, we should display an error message. Hw to check whether the...
4
1603
by: F159753 | last post by:
I have the following code: <script type="text/javascript"> function displayRow(){ var ET = document.getElementById("ExpenseTable"); var row3 = document.getElementById("searchbutton"); If row3.value == 'search' { if (row2.value == 'Expenses') {
0
8718
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,...
0
9198
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9104
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
9047
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
7973
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...
0
4477
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
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.