2014-10-20 1 views
0

Visual Studio에서 gridview가 있습니다. collumns 중 하나에 해당 파일 유형이 삽입 된 행을 기준으로 작은 아이콘 로고가 표시됩니다. 일단 아이콘이 클릭되면 첨부 파일을 열어야한다고 생각하는 코드를 만들었습니다. 내가 코드를 실행하면인덱스가 범위를 벗어났습니다. 음수가 아니어야하며 컬렉션의 크기보다 작아야합니다. VB.net Gridview

, 나는이 오류가 :

인덱스 범위를 벗어난 것입니다. 음수가 아니어야하며 콜렉션의 크기보다 작아야합니다. 매개 변수 (이름) : index(). 줄 530 : ImgBtn.Attributes.Add ("onClick", "javascript : window.open ('DisplayPM.aspx? ServiceID ="+ Service_History.DataKeys (e.Row.RowIndex) .Value.ToString + "');")

이 문제를 해결할 수 없습니다.

 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 + "');") 

는 내가 얻을 수있는 기대했다 : 이것은 GRIDVIEW RowDataBound에서 VB에서 내 코드

        <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> 

입니다 :

이것은 GRIDVIEW의 ASPX 내 코드입니다 내가 도움이 안되는 부분에 대한 도움. 미리 감사하십시오

+0

바인딩하기 전에 마크 업이나 코드에 DataKeys 속성을 설정 했습니까? – Steve

+0

방금 ​​마크 업에 데이터 키를 구현했으며 현재 작동 중입니다! 건배. @ 스티브 –

답변

0

나는 내 문제를 해결했습니다!

내가 넣어 필요 :

DataKeyNames="ServiceID,ID" 

을 gridview에 대한 마크 업에 지금은 잘 작동합니다.

2 일 후에 답변을 작성하겠습니다.

관련 문제