Coolite:GridPanel按SHIFT、Ctrl多行跳行选择,获取所选行主键及RowIndex

1.设置GridPanel允许按SHIFT、Ctrl多行、跳行选择

在GridPanel中添加如下代码

 

<SelectionModel>

<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />

</SelectionModel>

 

也可把ext:RowSelectionModel改为CheckboxSelectionModel

那么在GridPanel首列前的每行,会显示一排Checkbox

顺便提一下,添加<ext:RowNumbererColumn />代码,GridPanel自动显示每行行号

 

2.获取所选行主键及RowIndex

外面写个Button

 

  
    
< ext:Button ID = " Button3 " runat = " server " Text = " 处理完毕 " Icon = " ApplicationGo " >
< DirectEvents >
< Click OnEvent = " Button3_Click " />
</ DirectEvents >
</ ext:Button >

 

 

在Button3_Click事件下

 

protected void Button3_Click(object sender,DirectEventArgs e)

{

RowSelectionModel sm = this.TaskGridPanel.SelectionModel.Primary as RowSelectionModel;

foreach (SelectedRow row in sm.SelectedRows)

{

this.TaskGridPanel.Title += row.RecordID.ToString();//把所选行的主键显示在GridPanel的Title上

this.TaskGridPanel.Title += ":";

this.TaskGridPanel.Title += row.RowIndex.ToString();//row.RowIndex即获取所选行行号

this.TaskGridPanel.Title += ",";

}

}

 

需要注意的是

在Store里需要使用

<ext:JsonReader IDProperty="R1">//会过滤掉R1字段相同的行

row.RecordID取的是R1值

 

小弟初学Coolite,如有错误,麻烦高手们指出,O(∩_∩)O谢谢!

你可能感兴趣的:(gridPanel)