如何让 gridview 运行完自定义的事件后运行默认的事件

guostong 2007-08-20 12:51:20
一个 gridview 有 “edit”按钮,可以编辑数据,
我想实现一个点击一行任何地方时就选中当前行的功能,

添加了如下代码:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeComponent();
}
private void InitializeComponent()
{
gv_master.RowCommand += new GridViewCommandEventHandler(gv_master_RowCommand);
}

protected void gv_master_RowDataBound(object sender, GridViewRowEventArgs e)
{
// set single_click event to every column
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get the LinkButton control in the first cell
LinkButton singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
// Get the javascript which is assigned to this LinkButton
string jsSingle = ClientScript.GetPostBackClientHyperlink(singleClickButton, "");

// Add events to each editable cell
for (int columnIndex = m_iFirstColumn; columnIndex < e.Row.Cells.Count; columnIndex++)
{
// Add the column index as the event argument parameter
string js = jsSingle.Insert(jsSingle.Length - 2, columnIndex.ToString());
// Add this javascript to the onclick Attribute of the cell
e.Row.Cells[columnIndex].Attributes["onclick"] = js;
// Add a cursor style to the cells
e.Row.Cells[columnIndex].Attributes["style"] += "cursor:pointer;cursor:hand;";
}
}
}

#region Render Override

// Register the dynamically created client scripts
protected override void Render(HtmlTextWriter writer)
{
// The client events for GridView1 were created in GridView1_RowDataBound
foreach (GridViewRow r in gv_master.Rows)
{
if (r.RowType == DataControlRowType.DataRow)
{
for (int columnIndex = m_iFirstColumn; columnIndex < r.Cells.Count; columnIndex++)
{
Page.ClientScript.RegisterForEventValidation(r.UniqueID + "$ctl00", columnIndex.ToString());
}
}
}

base.Render(writer);
}

#endregion

protected void gv_master_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView gridView = (GridView)sender;
int rowIndex = int.Parse(e.CommandArgument.ToString());

switch (e.CommandName)
{
case ("single_click"):
gv_master.SelectedIndex = rowIndex;
break;
default:
break;

}
}

选中的功能实现了,但是“编辑”按钮不起作用了。请赐教
...全文
61 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,056

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧