PDA

View Full Version : [CLOSED] Update from 1.x to 2.x / #{store}.getAt(0).id trouble



tMp
Sep 07, 2013, 2:28 PM
Hello

In Ext.Net 1.x I was retrieving the id of a record at a store during a onChange direct event of a paging toolbar (pagesize = 1). Since I switched to Version 2.x and I am creating everything in code behind with direct methods I have a little trouble. As in the demo: Instead of the ID value I get a strange string that incoporates the id value at the end. Any idea how I can get the simple ID value back?

aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form" runat="server">

<ext:ResourceManager ID="ResourceManager" runat="server" />

<!-- TAB DETAILS -->
<ext:TabPanel runat="server" ID="TAB" MinTabWidth="100">
<Items>
<ext:Panel ID="PANEL" runat="server" Title="Panel"><DirectEvents><Activate OnEvent="loadTab" /></DirectEvents></ext:Panel>
</Items>
</ext:TabPanel>


</form>
</body>
</html>


cs:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{

}
}

protected void loadTab(object sender, DirectEventArgs e)
{
// create demo datatable
DataTable dt = new DataTable();

DataColumn dc = new DataColumn("ID");
dt.Columns.Add(dc);
dc = new DataColumn("VALUE");
dt.Columns.Add(dc);

DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["VALUE"] = "One";

dt.Rows.Add(dr);

dr = dt.NewRow();
dr["ID"] = "2";
dr["VALUE"] = "Two";

dt.Rows.Add(dr);

dr = dt.NewRow();
dr["ID"] = "3";
dr["VALUE"] = "Three";

dt.Rows.Add(dr);


// Build JOb Panel, add items and insert data
Ext.Net.Panel panel = new Ext.Net.Panel
{
Title = "Panel",
ID = "pnlPANEL",
Height = 600,
StyleSpec = "marginTop:10px",
Items =
{
new Ext.Net.DataView {
ID = "dv",
Padding = 5,
ItemSelector = "div",
DisableSelection = true,
Store = {
new Ext.Net.Store {
ID = "STORE_dv", PageSize = 1,
Model = {
new Ext.Net.Model {
Fields = {
new Ext.Net.ModelField { Name = "ID", Type = Ext.Net.ModelFieldType.String },
new Ext.Net.ModelField { Name = "VALUE", Type = Ext.Net.ModelFieldType.String }
},
IDProperty = "ID"
}
},
DataSource = dt,
Sorters = { new Ext.Net.DataSorter { Property = "VALUE", Direction = Ext.Net.SortDirection.DESC } }
}
},
Tpl = new XTemplate {
Html = @"<tpl for=""."">
<div>{ID}<br />{VALUE}
</div>
</tpl>"
}
}
},
BottomBar = {
new PagingToolbar {
HideRefresh = true,
StoreID = "STORE_dv",
DisplayMsg = "",
Listeners = { Change = { Handler = "App.direct.onChange(((#{STORE_dv}.getCount() > 0) ? #{STORE_dv}.getAt(0).id : ''));" } }
}
}
};

panel.AddTo(this.PANEL);
}

// On Change
[DirectMethod]
public void onChange(string ID)
{
X.Msg.Alert("Demo", ID).Show();
}
}

Thank you very much!

Daniil
Sep 09, 2013, 7:58 AM
Hi @tMp,

There are two possible solutions.

1. Please set up IDProperty="ID" for the Model and use:

#{STORE_dv}.getAt(0).getId()
instead of

#{STORE_dv}.getAt(0).id

or

2. Please use:

#{STORE_dv}.getAt(0).get('ID')
instead of

#{STORE_dv}.getAt(0).id

tMp
Sep 11, 2013, 12:40 PM
Perfect, thank you.