 |
|
|
 |
 |
|
ปัญหาการ Bind Data to Listbox on Gridview
คือว่าผมลองทำดูแล้วมันติด error แบบ นี้ น่ะครับ
Invalid attempt to Read when reader is closed
-> gridview.DataBind()
Code (ASP)
<%
<asp:GridView ID="GV_ShowPatient" runat="server" AutoGenerateColumns="False" CellPadding="1"
CellSpacing="3" DataKeyNames="RN" Font-Names="Angsana New" Font-Size="16pt" Width="942px">
<Columns>
<asp:TemplateField HeaderText="พยาบาล">
<ItemTemplate>
<asp:ListBox runat ="server" ID ="listboxNurse" DataSource ='<%# BindToListbox(DataBinder.Eval(Container,"DataItem.RN"))%>'></asp:ListBox>
</ItemTemplate>
<HeaderStyle BackColor="#66FFFF" HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
%>
Code (VB.NET)
Sub BindRecieveToGridview1(ByVal gridview As GridView)
conn.Connect() 'name_staff เอาแต่ driver
Mysql = "SELECT t.RN,t.StateSend,p.Name,c.carlicense,s.name_staff,t.insideSendTime,t.Date_Refer,t.Time_Refer FROM transrefer_table t,carrefer_table c,staff_table s,staffsending_table ss,patient_table p WHERE "
Mysql &= "(t.acceptType_acceptHos='1' AND t.acceptType_acceptBar='1')AND(t.CID=p.CID)AND(t.id_car=c.id_car)AND((t.RN=ss.RN)AND(ss.id_staff=s.id_staff)AND(s.type_staff='1'))AND(t.Status_SendPatientDouble='0')"
Dim cmm As New Mysql.Data.MySqlClient.MySqlCommand(Mysql, conn.myConnection)
conn.MyReader = cmm.ExecuteReader
If conn.MyReader.HasRows Then
gridview.Visible = True
gridview.DataSource = conn.MyReader
gridview.DataBind()
conn.MyReader.Close()
Else
MsgBox(" ไม่มีข้อมูล ", MsgBoxStyle.Critical, "asdf")
End If
End Sub
Public Function BindToListbox(ByVal VRN)
conn.MyReader.Close()
Mysql = "SELECT s.name_staff FROM staffsending_table ss,staff_table s WHERE ss.RN='" & VRN & "' AND ss.id_staff=s.id_staff AND s.type_staff='2'"
Dim cmm2 As New Mysql.Data.MySqlClient.MySqlCommand(Mysql, conn.myConnection)
conn.MyReader = cmm2.ExecuteReader
Return conn.MyReader
End Function
|
 |
 |
 |
 |
Date :
2009-06-07 14:08:22 |
By :
xman2548 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ reader bind เข้า gridview ไม่ได้คับ
คุณต้องใช้หลักการของ dataset หรือ datatable ลองอ่านดูคับ
|
 |
 |
 |
 |
Date :
2012-08-31 09:24:57 |
By :
unknown |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|