環境が無いので動作未確認。
もしかしたら動かないかもしれないです。
WebPage1.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebPage1.aspx.cs"
Inherits="WebPage1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>WebPage1</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView
id="GridView1"
runat="server"
OnRowCreated="GridView1_OnRowCreated"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Col1">
<ItemTemplate>
<%# Eval("Col1") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Col2">
<ItemTemplate>
<%# Eval("Col2") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
WebPage1.aspx.cs
using System;
using System.Data;
using System.Web.UI;
public class WebPage1 : Page, IPostBackEventHandler{
private DataTable _dt = null;
private const string VIEW_STATE_DT_NAME = "ViewStateDtName";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
_dt = new DataTable();
_dt.columns.add("col1");
_dt.columns.add("col2");
_dt.rows.add("A", "B");
_dt.rows.add("C", "D");
ViewState[VIEW_STATE_DT_NAME] = _dt;
GridView1.DataSource = _dt;
GridView.DataBind();
}else{
_dt = (DataTable)ViewState[VIEW_STATE_DT_NAME];
}
}
public void RaisePostBackEvent(string eventArgument)
{
// DoubleClick の PostBack で実行される
int rowIndex;
if(int.tryParse(eventArgyment, out rowIndex)){
string str = _dt[rowIndex][0];
}
}
protected void GridView1_RowCreated(Object sender, GridViewRowEventArgs e){
if(e.Row.RowType == DataControlRowType.DataRow)
{
// DubleClick に PostBack Script を設定
e.Row.Attributes.Add("ondblclick", Page.ClientScript.GetPostBackEventReference(this, e.Row.RowIndex.ToString());
}
}
}
最終更新:2013年10月30日 02:24