Grid行命令做操作时如何取得该行的字段值?

Jul 13, 2009 at 1:24 AM

Grid行命令做操作时如何取得该行的字段值?

Coordinator
Jul 14, 2009 at 2:45 AM

首先在页面中Grid定义DataKeyNames:

<ext:Grid ID="Grid1" Title="表格" ShowBorder="true" ShowHeader="true" Width="900px"
        AutoHeight="true" runat="server" EnableCheckBoxSelect="true" DataKeyNames="Id,Year,MyText"
        OnRowCommand="Grid1_RowCommand" OnPreRowDataBound="Grid1_PreRowDataBound" OnRowDataBound="Grid1_RowDataBound"
        EnableRowNumber="True">

然后在后台代码中:

 

protected void Grid1_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
{
            // 'Id-102,Year-2007,MyText-MY_Item2'
            object[] keyValues = Grid1.DataKeys[e.RowIndex];
            Alert.Show(String.Format("Id-{0},Year-{1},MyText-{2}", keyValues[0], keyValues[1], keyValues[2]));
}

Jul 14, 2009 at 4:46 AM

谢谢!