The gridview is used to display data during the two days of OA. To improve user experience. Write a single-host row event. The result showed that the gridview did not have this event, so I had to turn to Baidu.
Finally, the solution was found. Okay, I don't have to talk about it anymore. PasteCode
First, set a hidden buttonfield on the foreground.
<Columns>
<Asp: buttonfield visible ="False"TEXT ="Singleclick"Commandname ="Singleclick"/>
</Columns>
Write the code in the rowdatabound and rowcommand events.
Protected Void Gvroleinfos_rowdatabound ( Object Sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
Linkbutton _ singleclickbutton = (linkbutton) E. Row. cells [ 0 ]. Controls [ 0 ];
String _ Jssingle = clientscript. getpostbackclienthyperlink (_ singleclickbutton, "" );
E. Row. attributes [ " Onclick " ] = _ Jssingle;
}
}
Protected Void Gvroleinfos_rowcommand ( Object Sender, gridviewcommandeventargs E)
{
Gridview _ gridview = sender As Gridview;
Int _ Selectindex = Int . Parse (E. commandargument. tostring ());
String _ Commandname = E. commandname;
If (_ Commandname = " Singleclick " )
{
_ Gridview. selectedindex = _ selectindex;
}
}
Then rewrite the render method on this page.
Protected Override Void Render (htmltextwriter writer)
{
Foreach (Gridviewrow rowIn Gvroleinfos. Rows)
{
If (Row. rowtype = datacontrolrowtype. datarow)
{
Page. clientscript. registerforeventvalidation (row. uniqueid + " $ Ct100 " );
Page. clientscript. registerforeventvalidation (row. uniqueid + " $ Ct101 " );
Page. clientscript. registerforeventvalidation (row. uniqueid +" $ Ct102 " );
}
}
Base . Render (writer );
}
Address: http://www.cnblogs.com/webabcd/archive/2007/04/22/723113.html
Http://www.codeproject.com/KB/webforms/EditGridviewCells.aspx