我有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 page
<asp:GridView ID="gvKeywordSearch" runat="server" Width="100%"
AutoGenerateColumns="false" Visible="true"></asp:GridView>
答案 0 :(得分: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>