Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have to design a page in which a list of entries from a database are to be displayed as a table(either normal html table or maybe gridview or something.) with some checkboxes in it. The user should be able to select some options from these checkboxes and the selected value shud be updated to the database once when it is posted. I'm new to asp.net and c#.

As an example.
Consider an attendance mgmt system wherein the candidates are listed in a table with checkboxes that enables a person to select whether a person is present or absent and the person clicks an update button which posts that attendance data to a database.

Thanks in advance
Posted

1 solution

Hi,

Follow the steps below...

1. Add an item template columns with a checkbox to gridview.

2. Enable AutoPostBack of CheckBox

3. Handle the OnCheckedChangedEvent for Checkbox.

in the function write the following code.

CheckBox objCheck=sender as CheckBox;

GridViewRow objRow=objCheck.NamingContainer as GridViewRow;

GridViewRow objSelectedRow=GridView1.Rows[objRow.Index];

// Here you can extract the values from the cells of the Selected Row.

string strName=objSelectedRow.Cells[1]; // assuming that Cell[1] contains the name

// The Update Query can be then fired to update the data.

Regards,
RK
 
Share this answer
 
Comments
Sriram Mani 1-Nov-12 8:55am    
Thanks RK,
I'll try this and let you know the result. Thanks again.
Sriram Mani 27-Nov-12 23:58pm    
RK,
Your solution is working fine. Thanks. Please suggest some solution if i have multiple elements in a single cell in a row. Say a template field having radiobuttons, checkboxes and textboxes. Is there any possibilty to get the specific element value in a cell with multiple elements.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900