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

Discussion in '.NET' started by stavo23, Feb 26, 2008.

  1. stavo23

    stavo23

    Joined:
    Feb 26, 2008
    Messages:
    1
    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.ConnectionStrings["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: Feb 26, 2008
    stavo23, Feb 26, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    1
    Views:
    5,635
  2. Kirk
    Replies:
    2
    Views:
    1,799
  3. ebosysindia
    Replies:
    0
    Views:
    370
    ebosysindia
    May 8, 2009
  4. Kirk
    Replies:
    0
    Views:
    212
  5. rishabhshrivastava@gmail.com

    Getting the Values of CheckBox(es) Selected

    rishabhshrivastava@gmail.com, Jul 23, 2006, in forum: Javascript
    Replies:
    5
    Views:
    193
Loading...

Share This Page