0
我在Visual Studio中有一个gridview,其中一个collumns显示小图标标志的基础是哪个文件类型已经插入该行, 我有创建了一些代码,我相信一旦图标被点击就应该打开附加文件。指数超出范围。必须是非负的,并且小于集合的大小VB.net Gridview
当我运行代码,我得到这个错误:
指数超出范围。必须是非负数且小于集合的大小。参数(名称):index()。 Line 530:ImgBtn.Attributes.Add(“onClick”,“javascript:window.open('DisplayPM.aspx?ServiceID =”+ Service_History.DataKeys(e.Row.RowIndex).Value.ToString +“');” )
我无法绕过这个问题。
这是我在ASPX为GridView代码:
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="PdfExtention2" runat="server" ImageUrl="../icons/pdf.gif" Visible="false"/>
<asp:ImageButton ID="WordExtention2" runat="server" ImageUrl="../icons/actn103.gif" Visible="false"/>
<asp:ImageButton ID="ExcelExtention2" runat="server" ImageUrl="../icons/actn102.gif" Visible="false"/>
</ItemTemplate>
<ItemStyle Width="25%" />
</asp:TemplateField>
这是我在VB代码在GridView的RowDataBound:
Dim pdfExtention2, wordExtention2, excelExtention2 As ImageButton
pdfExtention2 = e.Row.FindControl("PdfExtention2")
wordExtention2 = e.Row.FindControl("WordExtention2")
excelExtention2 = e.Row.FindControl("ExcelExtention2")
If e.Row.DataItem("Extention").ToString = "application/pdf" Then
pdfExtention2.Visible = True
ElseIf e.Row.DataItem("Extention").ToString = "application/msword" Then
wordExtention2.Visible = True
ElseIf e.Row.DataItem("Extention").ToString = "application/vnd.ms-excel" Then
excelExtention2.Visible = True
End If
'-----------------------------------------------------------------
Dim ImgBtn As New ImageButton
ImgBtn = e.Row.FindControl("PdfExtention2")
ImgBtn.Attributes.Add("onClick", "javascript:window.open('DisplayPM.aspx?ServiceID=" + Service_History.DataKeys(e.Row.RowIndex).Value.ToString + "');")
Dim ImgBtn2 As New ImageButton
ImgBtn2 = e.Row.FindControl("WordExtention2")
ImgBtn2.Attributes.Add("onClick", "javascript:window.open('DisplayPM.aspx?ServiceID=" + Service_History.DataKeys(e.Row.RowIndex).Value.ToString + "');")
Dim ImgBtn3 As New ImageButton
ImgBtn3 = e.Row.FindControl("ExcelExtention2")
ImgBtn3.Attributes.Add("onClick", "javascript:window.open('DisplayPM.aspx?ServiceID=" + Service_History.DataKeys(e.Row.RowIndex).Value.ToString + "');")
我希望我能得到一些协助我去哪里错了。 Thankyou提前
您是否在绑定之前在标记或代码中设置了DataKeys属性? – Steve 2014-10-20 10:25:24
我刚刚在我的标记中实现了数据密钥,现在它正在工作!干杯。 @Steve – 2014-10-20 10:44:33