Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting selected values from gridview (checkbox) and inserting the Id in the database

Thread Tools

Getting selected values from gridview (checkbox) and inserting the Id in the database

stavo23 stavo23 is offline
Junior Member
Join Date: Feb 2008
Posts: 1

I have a gridview and a dropdownlist. I want to get the selected value from the dropdownlist and all the checked values in the gridview and insert them into the datbase through a stored proc.

Here is my code:

protected void btnAddToList_Click(object sender, EventArgs e)
for (int z = 0; z < this.gvViewList.Rows.Count; z++)

bool ifchecked = ((CheckBox)gvViewList.Rows[z].FindControl("chkSelect")).Checked;
//int id = ((CheckBox)gvViewList.Rows[z].FindControl("chkSelect")).Checked;
if (ifchecked)

SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrin gs["Eddition2ConnectionString"].ToString());

SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "procinsert"
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@ListID", ddlList.SelectedValue));
cmd.Parameters.Add(new SqlParameter("@UserID.SelectedValue));

if (cn != null)


my frontend

<asp:TemplateField HeaderText="Select">
<asp:CheckBox ID="chkSelect" runat="server" />
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server"
type="checkbox" />

Last edited by stavo23; 02-26-2008 at 03:28 PM..
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase Computer Information 0 09-26-2012 09:40 AM
How to get values from selected item in a gridview Julia B ASP .Net 0 10-08-2008 02:08 PM
Getting CheckBoxList selected values Patrick Olurotimi Ige ASP .Net 1 06-16-2005 08:52 AM
Getting selected text values =?Utf-8?B?SGFzc2FuIEJhc3NhbQ==?= ASP .Net 5 02-28-2005 03:27 PM