 |
|
Add ข้อมูล ลง gridview คือผมมี ฟิลด์ให้ user ใส่ 3 ฟิลด์ Barcode, OrderID, Qty. และก็มีปุ่ม Add แล้วผมก็มีตัว gridview ไว้โชว์ข้อมูล |
|
 |
|
|
 |
 |
|
จะต้องวาง textbox ไว้ในส่วน footer ของ GridView น่ะครับ แล้วเพิ่มปุ่ม Submit เป็น
<asp:Button id="btnAdd" runat="server" Text="Add" CommandName="Add"></asp:Button>
และในส่วนของ Code ให้ใช้
Code (VB.NET)
Sub myGridView_RowCommand(source As Object, e As GridViewCommandEventArgs)
If e.CommandName = "Add" Then
'*** CustomerID ***'
Dim txtCustomerID As TextBox = CType(myGridView.FooterRow.FindControl("txtAddCustomerID"), TextBox)
'*** Email ***'
Dim txtName As TextBox = CType(myGridView.FooterRow.FindControl("txtAddName"), TextBox)
'*** Name ***'
Dim txtEmail As TextBox = CType(myGridView.FooterRow.FindControl("txtAddEmail"), TextBox)
'*** CountryCode ***'
Dim txtCountryCode As TextBox = CType(myGridView.FooterRow.FindControl("txtAddCountryCode"), TextBox)
'*** Budget ***'
Dim txtBudget As TextBox = CType(myGridView.FooterRow.FindControl("txtAddBudget"), TextBox)
'*** Used ***'
Dim txtUsed As TextBox = CType(myGridView.FooterRow.FindControl("txtAddUsed"), TextBox)
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
" VALUES ('" & txtCustomerID.Text & "','" & txtName.Text & "','" & txtEmail.Text & "' " & _
" ,'" & txtCountryCode.Text & "','" & txtBudget.Text & "','" & txtUsed.Text & "') "
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
BindData()
End If
End Sub
Ref : ASP.NET GridView Control - RowCommand
|
 |
 |
 |
 |
Date :
2009-02-04 09:58:44 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Add เสด แล้วค่อย insert ทีหลังได้มั๊ยครับ
แบบนี้ เหมือนว่า พอกด Add มันก็ insert เลยอะครับ
|
 |
 |
 |
 |
Date :
2009-02-04 10:54:43 |
By :
mixarstudio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|