◀ Previous Next ▶ Up ▲


witpoko.com


ถามเรื่อง Code ASP.NET คับบ ติด Error คับบ

คือ Code ผมประมาณว่า

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
OnPageIndexChanging="ShowPageCommand" AllowPaging="True" ShowFooter="True" >
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<Columns>
<ItemTemplate>
<asp:TextBox ID="sale_num" runat="server" Text = "0"></asp:TextBox>
</ItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Buy" CommandName="Buy" ></asp:Button>
</ItemTemplate>
</Columns>
</asp:GridView>
' ------------------------------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack() Then
Dim StrConn As String = WebConfigurationManager.ConnectionStrings("conn").ConnectionString
Dim dt As New DataTable
Dim da1 As New System.Data.SqlClient.SqlDataAdapter("SELECT * FROM mode", StrConn)
da1.Fill(dt)
Dim LT As New ListItem
'LT.Text = "-- Select Mode --"
'LT.Value = ""
'mode.Items.Add(LT)

For i As Integer = 0 To dt.Rows.Count - 1
mode.Items.Add(New ListItem(dt.Rows(i).Item("mode"), dt.Rows(i).Item("id_mode")))
Next
End If
Gridbind()
End Sub

Sub Gridbind()
Dim strConn As String
Dim sqluername As String

strConn = WebConfigurationManager.ConnectionStrings("conn").ConnectionString

Dim Conn As New SqlConnection(strConn)
Conn.Open()

sqluername = "SELECT * FROM drug,mode WHERE mode.id_mode='" & mode.Text & "'AND mode.id_mode = drug.id_mode order by name_drug,lot_num "

Dim da As New SqlDataAdapter(sqluername, Conn)
Dim ds As New DataSet
da.Fill(ds, "drug")

GridView1.DataSource = ds.Tables("drug")
GridView1.DataBind()

End Sub

Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Buy" Then
For Each gr As GridViewRow In Me.GridView1.Rows
If gr.RowType = DataControlRowType.DataRow Then

Dim tmpTextbox As TextBox = gr.Cells(5).FindControl("sale_num")

If tmpTextbox IsNot Nothing Then

Me.Session("aaaa") = tmpTextbox.Text
Response.Write(tmpTextbox.Text)

End If
End If
Next
End If
End Sub

คือพอคลิกปุ่ม Buy แล้ว Error เลยคับ ช่วยแนะนำทีว่าผิดตรงไหน ขอบคุณคับบบ


จากคุณ : hero -[ 30 ม.ค. 52 - 23:39:49 A:118.174.150.62 X: ]





กระทู้ยอดนิยม