Select many CheckBox on GridPanel Ext.Net (ASP.NET)

671 views Asked by At

How to select Rows on GridPanel using ext.net Library on ASP.NET. When i put this code on Page_Load event, it's work fine :

  protected void Page_Load(object sender, EventArgs e)
    {
      RowSelectionModel sm = gridRolesPermission.GetSelectionModel() as RowSelectionModel;
        sm.SelectedRows.Add(new SelectedRow(1));
        sm.SelectedRows.Add(new SelectedRow(2));
    }

but when i would to select CheckBoxs on Ajax event, it's not working !

  [DirectMethod]
        public void FillPermissionForSelectedRole()
        {
        RowSelectionModel sm = gridRolesPermission.GetSelectionModel() as RowSelectionModel;
        sm.SelectedRows.Add(new SelectedRow(1));
        sm.SelectedRows.Add(new SelectedRow(2));
        }

On view :

....
<Listeners>
<Command Handler="App.direct.FillPermissionForSelectedRole();" />
</Listeners>
...

Any Help Please !

2

There are 2 answers

0
AHmedRef On BEST ANSWER

to resolve this probleme i should add this line to upadate modifications :

sm.UpdateSelection();
0
sakir On

In your example,when u click the button(directMethod button),a pamatercollection sent to the server called CheckboxSelectionModel1 .on server side, u can get the this parameter collection like this.

string hh= HttpContext.Current.Request["CheckboxSelectionModel1"];

*CheckboxSelectionModel1 is the model name of the grid on your example.

in your case like that

[DirectMethod]
        public void FillPermissionForSelectedRole()
        {
 string hh= HttpContext.Current.Request["CheckboxSelectionModel1"];

        }

string hh should be something like this depents on the what u checked on grid.

"[{"RecordID":5,"RowIndex":5},{"RecordID":7,"RowIndex":7},{"RecordID":3,"RowIndex":3}]"

later u can desrialize this string and get the RecordID something like this

    var rw = JSON.Deserialize<Row[]>(hh);
    string txt = "";
    foreach (var item in rw)
    {
        txt += item.RecordID;
    }

and the row class

public  class Row{
            public string RecordID { get; set; }
            public string RowIndex { get; set; }

        }