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");
}
이 코드를 실행할 때 형식 예외가 발생하고 다시 이유가 확실하지 않습니다. 이미지 버튼을 약간 변경하고 더 정확한 링크 버튼으로 이미지를 중첩했습니다. 아마도
관련
원래 감사합니다. 도움을 주셔서 감사합니다. – Arianule