•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 397,646 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,452 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 645 | Replies: 5
![]() |
•
•
Join Date: May 2008
Posts: 23
Reputation:
Rep Power: 1
Solved Threads: 0
hi....
I have a gridview with rows of info which does not go into edit mode.
A user clicks a checkbox which picks that item and adds a Unit Price
What i need to do is when a user clicks on a button, it should scan through the gridview for all items checked and pick up the Unit Price values and a couple of other field values and insert the information into a sql database
What would be the best way of doing this?
Thanks in advance!
I have a gridview with rows of info which does not go into edit mode.
A user clicks a checkbox which picks that item and adds a Unit Price
What i need to do is when a user clicks on a button, it should scan through the gridview for all items checked and pick up the Unit Price values and a couple of other field values and insert the information into a sql database
What would be the best way of doing this?
Thanks in advance!
on button click event u jusst check what are the checkboxexs clicked.
u can use this function
u can use this function
asp.net Syntax (Toggle Plain Text)
submit_click { for(int i=0;i<=gridview.rows.count-1;i++) { checkbox chk=new checkbox(); chk=(checkbox)gridview.rows[i].findcontrol("chk_name"); if(chk.checked) { //write the code needed to get unit prices and insert into database } } }
Last edited by peter_budo : Jul 7th, 2008 at 7:00 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: May 2008
Posts: 23
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
on button click event u jusst check what are the checkboxexs clicked.
u can use this function
submit_click
{
for(int i=0;i<=gridview.rows.count-1;i++)
{
checkbox chk=new checkbox();
chk=(checkbox)gridview.rows[i].findcontrol("chk_name");
if(chk.checked)
{
write the code needed to get unit prices and insert into database
}
}
}
hello thanks for the quick reply...
my problem is how to wirte an SQL statement to insert multiple records.. can you please give me an idea or the code for inserting checked records. i dont konw what code to put in this line
write the code needed to get unit prices and insert into database
}
}
•
•
Join Date: May 2008
Posts: 23
Reputation:
Rep Power: 1
Solved Threads: 0
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString());
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox chkbox = (CheckBox)row.FindControl("chkboxSelect");
TextBox UnitPrice = (TextBox)row.FindControl("txtUnitPrice");
if (chkbox.Checked == true)
{
try
{
conn.Open();
int Supp = Convert.ToInt16(Request.QueryString["SupplierId"]);
SqlCommand cmd = new SqlCommand ("INSERT INTO SuppMat (SupplierId, MaterialID, UnitPrice) VALUES (@SupplierId,'" + row.Cells[1].Text + "','" + UnitPrice.Text + "')", conn);
cmd.Parameters.AddWithValue("@SupplierId", Supp);
cmd.ExecuteNonQuery();
conn.Close();
}
catch
{
Response.Write("");
}
finally
{
conn.Close();
}
}
}
}here's my code..my only problem now is that it does not save to the database.. hope you can help me..
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
Similar Threads
Other Threads in the ASP.NET Forum
- Previous Thread: reading aspx tags and storing
- Next Thread: Disable 'Back' button on browser


Linear Mode