0

我有 DataTable 的数据。分配给 gridview ,但 gridview 在分配后有 0 行。

         Dim mKeywordSearch As New KeywordSearch
         Dim dtExcel As DataTable
         dtExcel = mKeywordSearch.DatabaseKeywordSearch(txtKeyword.Text)
         gvKeywordSearch.DataSource = dtExcel
         gvKeywordSearch.DataBind()
         Dim cnt As Integer = dtExcel.Rows.Count
         cnt = gvKeywordSearch.Rows.Count()

.aspx 页面

<asp:GridView ID="gvKeywordSearch" runat="server" Width="100%" 
AutoGenerateColumns="false" Visible="true"></asp:GridView>
4

1 回答 1

2

根据需要将 GridView 更改为AutoGenerateColumns="true"或定义列AutoGenerateColumns="false"

<asp:GridView ID="gvKeywordSearch" runat="server" Width="100%" 
AutoGenerateColumns="true" Visible="true"></asp:GridView>

或与AutoGenerateColumns = "false"

<asp:GridView ID="gvKeywordSearch" runat="server" Width="100%" 
    AutoGenerateColumns="false" Visible="true">
   <Columns>
      <asp:BoundField HeaderText="HeaderText1" DataField="FieldName1" ></asp:BoundField>
      <asp:BoundField HeaderText="HeaderText2" DataField="FieldName2" ></asp:BoundField>
      ...
   </Columns>
</asp:GridView>
于 2013-01-18T19:55:37.607 回答