Jun 19, 2009, 10:31 AM
Refresh gridpanel after adding SelectedRow from AjaxMethod
Hi,
i have a question: if i click button "btn", some rows will be checked. How to solve this without using session or hidden variable, etc
i have a question: if i click button "btn", some rows will be checked. How to solve this without using session or hidden variable, etc
<%@ Page Language="C#" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public class Vani
{
public Vani(string a, string b)
{
this.VALUE = a;
this.VALUE2 = b;
}
public string VALUE { get; set; }
public string VALUE2 { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FormLayout schemaFL = new FormLayout();
Anchor a = new Anchor();
a.Horizontal = "95%";
JsonReader ar = new JsonReader();
RecordField rf = new RecordField("VALUE", RecordFieldType.String);
RecordField rf2 = new RecordField("VALUE2", RecordFieldType.String);
ar.Fields.Add(rf);
ar.Fields.Add(rf2);
Store myStore = new Store();
myStore.ID = "Store1";
myStore.Reader.Add(ar);
myStore.DataSource = new List<Vani>
{
new Vani("1", "1"),
new Vani("2", "2"),
new Vani("3", "3"),
new Vani("4", "4")
};
this.form1.Controls.AddAt(0, myStore);
myStore.DataBind();
GridPanel grid = new GridPanel();
grid.ID = "myGrid";
grid.Width = Unit.Pixel(300);
grid.Height = Unit.Pixel(300);
grid.StoreID = "Store1";
CheckboxSelectionModel csm = new CheckboxSelectionModel();
csm.ID = "csm";
grid.SelectionModel.Add(csm);
Coolite.Ext.Web.Column col = new Coolite.Ext.Web.Column();
col.ColumnID = "colID";
col.Width = Unit.Pixel(150);
col.Header = "Column1";
col.DataIndex = "VALUE";
col.Sortable = true;
Coolite.Ext.Web.Column col2 = new Coolite.Ext.Web.Column();
col2.ColumnID = "colID2";
col2.Width = Unit.Pixel(100);
col2.Header = "Column2";
col2.DataIndex = "VALUE2";
col2.Sortable = true;
grid.ColumnModel.Columns.Add(col);
grid.ColumnModel.Columns.Add(col2);
a.Items.Add(grid);
schemaFL.Anchors.Add(a);
Panel1.Items.Add(schemaFL);
}
}
[AjaxMethod]
public void Btn()
{
GridPanel myGrid = (GridPanel)Panel1.FindControl("myGrid");
CheckboxSelectionModel csm = (CheckboxSelectionModel)myGrid.SelectionModel.Primary;
//for example, i want to check two rows
csm.SelectedRows.Add(new SelectedRow(1));
csm.SelectedRows.Add(new SelectedRow(2));
// i want to refresh gridpanel here, but i dont know how to do that
// ....
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server">
</ext:ScriptManager>
<ext:Panel runat="server" ID="Panel1" Width="504" Height="450" Title="DOCUMENT" Icon="BookAddresses">
<Body>
<ext:Button runat="server" Text="Submit" ID="btn">
<Listeners>
<Click Handler="Coolite.AjaxMethods.Btn();" />
</Listeners>
</ext:Button>
</Body>
</ext:Panel>
</form>
</body>
</html>