开发者

Insert data into Access database upon checkbox-click event of ASP.net

开发者 https://www.devze.com 2023-03-28 04:59 出处:网络
I\'m trying to make asp.net page Criteria I have product list. (using listview) ProductIDProudct namePriceADD TO CART(checkbox)

I'm trying to make asp.net page

Criteria

I have product list. (using listview)

ProductID    Proudct name      Price        ADD TO CART(checkbox)

Now I am using access 2007 for database. C# for code behind file. I want add product in to database which is on the event of checkbox. So if user check 10 item check box Ou开发者_如何学Got of 20 . I want write insert query on event of checkbox

Is it possible to do it? If it possible please provide me knowledge/ code how can I do it?

Please keep in mid that I am new and learning stage so make it easy or put gudieline in comments.


It sounds like you want to use the OnCheckedChanged event.

<asp:CheckBox ID="CheckBox1" runat="server" Text="Hello World!" OnCheckedChanged="CheckBox1_CheckedChanged" />

And in your code behind:

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    //CREATE CONNETION HERE
    OleDbConnection conn = new OleDbConnection ("<YOUR CONNECTION STRING HERE>");
    OleDbCommand command = new OleDbCommand();
    command.Connection = conn;

    //CREATE YOUR OWN INSERT/UPDATE COMMAND HERE
    command.CommandText= "<YOUR COMMAND TEXT HERE>";
    command.Parameters.Add ("@Argument1", OleDbType.String).Value = CheckBox1.Text;        
    command.ExecuteNonQuery();
    conn.Close();    
}
0

精彩评论

暂无评论...
验证码 换一张
取 消