Velocity Reviews - Computer Hardware Reviews

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

Reply
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
 
      02-26-2008
Greetings

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();
try
{
cn.Open();
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));


}
finally
{
if (cn != null)
{
cn.Close();
}
}
}

}

my frontend



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

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

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 scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com 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



Advertisments