2011-05-02 4 views
1

안녕 난이 같은 일부 코드를 추가하는 정규 Button 제어 할 ItemTemplate 같이 동일한 GridView 표시되는 GridView 제어의 일부로서 ImageButton 제어 할 내의하여 ImageButton에 기능을 추가 .gridview에 존재

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "addToSession") 
    { 
     //get the row index stored in the CommandArgument property 
     int index = Convert.ToInt32(e.CommandArgument); 

     //get the gridview row where the command is raised 
     GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index]; 

     //values stored in the text property of the cells 
     string ISBN = selectedRow.Cells[0].Text; 
     string bookTitle = selectedRow.Cells[1].Text; 
     string image = selectedRow.Cells[2].Text; 

     Service s = new Service(); 
     Session["ISBN"] = ISBN; 
     Session["bookTitle"] = bookTitle; 
     Session["ImageUrl"] = s.returnImageUrl(bookTitle); 

     if (Session["userName"] == null) 
     { 
      Response.Redirect("registerPage.aspx"); 
     } 
     else 
     { 
      Response.Redirect("RateBook.aspx"); 
     } 
    } 
    else if (e.CommandName == "ratedBooks") 
    { 
     int index = Convert.ToInt32(e.CommandArgument); 

     GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index]; 

     string bookTitle = selectedRow.Cells[1].Text; 

     Service s = new Service(); 

     Session["ImageUrl"] = s.returnImageUrl(bookTitle); 

     Response.Redirect("BookRated.aspx"); 
    } 

이 코드를 실행할 때 형식 예외가 발생하고 다시 이유가 확실하지 않습니다. 이미지 버튼을 약간 변경하고 더 정확한 링크 버튼으로 이미지를 중첩했습니다. 아마도

관련

답변

0

ImageButton.CommandName을 수행하는 것과 같은

<asp:TemplateField> 
       <ItemTemplate> 
        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="ratedBooks"> 
         <asp:Image ID="ImageButton1" ImageUrl='<%#Eval("pictureUrl") %>' 
          runat="server" /> 

        </asp:LinkButton>  

       </ItemTemplate> 
      </asp:TemplateField> 

조언 유효한 재산이며 Button.CommandName와 동일하게 작동합니다.

그러면 문제는 GridView1_RowCommand 절차에있을 가능성이 큽니다. ImageButton click을 처리 할 부분을 포함하여 전체 절차 코드를 게시 할 수 있습니까?

+0

원래 감사합니다. 도움을 주셔서 감사합니다. – Arianule