如何让 gridview 运行完自定义的事件后运行默认的事件
一个 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;
}
}
选中的功能实现了,但是“编辑”按钮不起作用了。请赐教