开头
好久没有写了,这次写的是一个很简单的方法,大概的样子就像下图,点击Display后需要得到GridiviewRow对象。
正文
很自然想到的第一个方法就是Parent属性,使用两个Parent就可以得到GridviewRow对象,第一个Parent得到的是DataControlFieldCell。
protected
void
btnDisplay_Command(
object
sender, CommandEventArgs e)
{
Button btnDisplay = sender as Button;
GridViewRow row = btnDisplay.Parent.Parent as GridViewRow;
}
{
Button btnDisplay = sender as Button;
GridViewRow row = btnDisplay.Parent.Parent as GridViewRow;
}
第二个方法就比较便利,直接使用NamingContainer,可以得到GridviewRow。
protected
void
btnDisplay_Command(
object
sender, CommandEventArgs e)
{
Button btnDisplay = sender as Button;
GridViewRow row = btnDisplay.NamingContainer as GridViewRow;
}
{
Button btnDisplay = sender as Button;
GridViewRow row = btnDisplay.NamingContainer as GridViewRow;
}