ページの読み込み:-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Page.Title = "Batches - " & Website
BindBatches()
Catch ex As Exception
Logger.WriteError("Error in Page_Load of Batches/batches.aspx", ex)
End Try
End Sub
このサブルーチンは、グリッドビューでbatch_nameをバインドします
Protected Sub BindBatches()
Try
Dim ds As New DataSet()
ds = Dal.ExecuteDataset("select batch_name from tblBatch")
If Not ds Is Nothing AndAlso ds.Tables(0).Rows.Count > 0 Then
gvBatches.DataSource = ds
gvBatches.DataBind()
gvBatches.Visible = True
Else
gvBatches.Visible = False
End If
Catch ex As Exception
Logger.WriteError("Error in BindBatches of Batches/batches.aspx", ex)
End Try
End Sub
これがgridviewです:-
<asp:GridView ID="gvBatches" runat="server">
<Columns>
<asp:TemplateField HeaderText="Batch Name">
<HeaderStyle Width="40px"></HeaderStyle>
<ItemTemplate>
<asp:Label ID="lblBatchName" runat="server">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
そしてデータバウンドイベント:-
Protected Sub gvBatches_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBatches.RowDataBound
If e.Row.RowType = ListItemType.Item Or e.Row.RowType = ListItemType.AlternatingItem Then
Dim batchName As Label = e.Row.FindControl("lblBatchName")
batchName.Text = e.Row.DataItem("batch_name")
End If
End Sub
しかし、デバッグすると、以下の例外が表示されます--gvBatches.DataBind()
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'id'.
このIDが何なのかわかりませんか?私のテーブルにはそのような列はありません。