我有从 datagridview 导出到 Excel 的功能,我通过按 Tab 键来尝试点击界面上的每个按钮来进行测试,以将指示器定位到每个按钮。但是在导出按钮上时。它给了我一个错误
DataGrid with id '' could not automatically generate any columns from the selected data source.
但是当我用指针/鼠标单击它时,它工作正常。
这是我导出到 excel 代码:
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
Dim dt As New DataTable
If CInquiry.SearchInquiry(txtAccount.Text, txtCustName.Text, txtAmount.Text, dropResponse.SelectedValue.ToString, txtInquiryDate.Text) Then
dt = CInquiry.DT
Else
eMessage(CInquiry.eMsg)
End If
Dim DataGrd As New DataGrid()
DataGrd.DataSource = dt.DefaultView
DataGrd.DataBind()
Dim attachment As String
attachment = "attachment; filename=Inquiry_Report" & Format(Now, "ddMMMyyyy") & ".xls"
Response.Buffer = True
Response.ClearContent()
Response.ClearHeaders()
Response.AddHeader("content-disposition", attachment)
Response.ContentType = "application/ms-excel"
Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
DataGrd.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()
End Sub
错误是当数据网格尝试绑定数据时,只有当我按照上面所说的操作时才会出现错误。怎么了?它是 onclick 它的意思是仅通过指针/鼠标单击吗?