Robert
Robert

Reputation: 1794

Ext.NET GridPanel with XML datasource

In the .aspx file I have:

<asp:XmlDataSource runat="server" ID="XmlDS" />
...
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:GridPanel
                                           ID="GridPanel1"
                                           runat="server"
                                           StripeRows="true"
                                           Title="User Permissions"
                                           TrackMouseOver="true"
                                           Width="600"
                                           Height="350"
                                           AutoExpandColumn="Item">
                                           <Store>
                                                <ext:Store ID="Store1" runat="server">
                                                     <Reader>
                                                         <ext:ArrayReader>
                                                             <Fields>
                                                                   <ext:RecordField Name="Item" /> 
                                                                   <ext:RecordField Name="Access1" Type="Boolean" />
                                                                   <ext:RecordField Name="Access2" Type="Boolean" />
                                                                   <ext:RecordField Name="Access3" Type="Boolean" />
                                                                   <ext:RecordField Name="Access4" Type="Boolean" />
                                                                   <ext:RecordField Name="Access5" Type="Boolean" />
                                                             </Fields>
                                                         </ext:ArrayReader>
                                                     </Reader>
                                                </ext:Store>
                                          </Store>
                                          <ColumnModel ID="ColumnModel1" runat="server">
                                              <Columns>
                                                  <ext:Column ColumnID="Item" Header="Item" DataIndex="Item" />
                                                  <ext:Column ColumnID="Access1" Header="Access1" DataIndex="Access1" />
                                                  <ext:Column ColumnID="Access2" Header="Access2" DataIndex="Access2" />
                                                  <ext:Column ColumnID="Access3" Header="Access3" DataIndex="Access3" />
                                                  <ext:Column ColumnID="Access4" Header="Access4" DataIndex="Access4" />
                                                  <ext:Column ColumnID="Access5" Header="Access5" DataIndex="Access5" />
                                              </Columns>
                                          </ColumnModel>
                                          <SelectionModel>
                                              <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                                          </SelectionModel>
                               </ext:GridPanel>

Note that I have no experience with ExtJS/Ext.NET so the GridPanel code was used according to how the panel is used on http://forums.ext.net/showthread.php?10205-More-Information-Required

There it is using a JSON object. Before attempting the whole ExtJS method I found that it can use XML or JSON. When a drop down list's selected index changes, it loads that user's permissions and adds it to a DataTable object (rows are string, bool, bool, bool, bool, bool), which I have successfully created the XML object for. The function returns a string (tempData) which is the address for the XML document in question. so here is the code where I'm not getting any result to load in the grid:

if (tempData != String.Empty)
        {
            XmlDS.DataFile = tempData;
            Store1.DataSource = XmlDS;
            Store1.DataBind();
            GridPanel1.Reload();
            File.Delete(tempData);
        }

tried GridPanel1.RefreshView() and it said it requires an AJAX Request and couldn't find anything on it. Reload() doesn't do what I am attempting to make it do (doesn't throw an exception like RefreshView() and passes right through fine, but doesn't load the data.

I'm thinking the GridPanel stuff was borrowed from where a JSON object was used, and perhaps the fact that a asp:XmlDataSource object isn't usable for it. But I really don't have a clue to how to get it to load this data

I have also tried setting the datasource to the table itself, which loads data, but it loads the string values as empty strings and loads all of the boolean values as false.

I appreciate any help you can give. If more info is needed, please let me know.

Thanks,


I cannot get it to load the XML for the life of me. I found an example on the ext.net site (the same one given by Geoffrey) that uses .xml and .xsl files. I generate the .xml document using c# but I don't have a .xsl file that goes with it (nor am I sure how a .xsl document should be structured to try and generate one).

So I have attempted to pass a DataTable object with 15 rows. End result:

enter image description here

One thing that is neat to note is that while it may not have the data, it does contain all 15 rows. I'm assuming it did try to load the dataset but just failed.

In the .aspx file I have:

<ext:ResourceManager ID="ResourceManager1" runat="server" />
                                  <ext:GridPanel
                                           ID="GridPanel1"
                                           runat="server"
                                           StripeRows="true"
                                           Title="User Permissions"
                                           TrackMouseOver="true"
                                           Width="600"
                                           Height="350"
                                           AutoExpandColumn="Item">
                                           <Store>
                                                <ext:Store ID="Store1" runat="server">
                                                     <Reader>
                                                         <ext:JsonReader>
                                                             <Fields>
                                                                   <ext:RecordField Name="Item" /> 
                                                                   <ext:RecordField Name="Access1" Type="Boolean" />
                                                                   <ext:RecordField Name="Access2" Type="Boolean" />
                                                                   <ext:RecordField Name="Access3" Type="Boolean" />
                                                                   <ext:RecordField Name="Access4" Type="Boolean" />
                                                                   <ext:RecordField Name="Access5" Type="Boolean" />
                                                             </Fields>
                                                         </ext:JsonReader>
                                                     </Reader>
                                                </ext:Store>
                                          </Store>
                                          <ColumnModel ID="ColumnModel1" runat="server">
                                              <Columns>
                                                  <ext:Column ColumnID="Item" Header="Item" DataIndex="Item" />
                                                  <ext:CheckColumn ColumnID="Access1" Header="Access1" DataIndex="Access1" Editable="true" Width="40px" /> 
                                                  <ext:CheckColumn ColumnID="Access2" Header="Access2" DataIndex="Access2" Editable="true" Width="40px" />
                                                  <ext:CheckColumn ColumnID="Access3" Header="Access3" DataIndex="Access3" Editable="true" Width="40px" />
                                                  <ext:CheckColumn ColumnID="Access4" Header="Access4" DataIndex="Access4" Editable="true" Width="40px" />
                                                  <ext:CheckColumn ColumnID="Access5" Header="Access5" DataIndex="Access5" Editable="true" Width="40px" />
                                              </Columns>
                                          </ColumnModel>
                                          <SelectionModel>
                                              <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                                          </SelectionModel>
                               </ext:GridPanel>

And this is the part where I'm attempting to load the data (tempData is the string address for the XML document as the xml is generated after a drop down list selection).

List<List<Object>> PermissionList = BL.Person.getPermissionsList(Convert.ToInt32(ddlUserName.SelectedValue));

        DataTable table = BL.Data.CreatePermissionsTable(PermissionList);

        string tempData = BL.Data.CreateXML(table, "Permission", Convert.ToInt32(ddlUserName.SelectedValue));

        if (tempData != String.Empty)
        {
            ChangeAccess.Style.Add("display", "block");
            Store1.DataSource = table;
            Store1.DataBind();
            File.Delete(tempData);
        }

note that when using the DataSet as the object, the string tempdata/file.delete are fairly pointless.

The end goal is to use XML but if it requires using DataTable in the meantime, then I'll go that route. The reason I'm not currently using the json/ method is that the data is, as mentioned, generated from the code behind (it generates 'true' values in the existence of a value in the useraccess for item/personid/accesslevel table, false otherwise. Not actual database entries).

Thanks again,


XML structure:

<permissions>
    <permission>
        <Item>Process 1</Item>
        <Access1>True</Access1>
        <Access2>True</Access2>
        <Access3>False</Access3>
        <Access4>False</Access4>
        <Access5>False</Access5>
    </permission>
    <permission>
        <Item>Process 2</Item>
        <Access1>True</Access1>
        <Access2>True</Access2>
        <Access3>True</Access3>
        <Access4>False</Access4>
        <Access5>False</Access5>
    </permission>
</permissions>

I attempted to reload the .XML again and this time it seems to be pulling, sort of, the rows generated are somewhere in the neighborhood of 100 rows returned (way beyond the 15 permission elements).

Note that I do not have a .xsl file for TransformFile. This won't be an issue I hope?

I need to log into the desktop with the actual code, I'll try and get the render thing you requested. Thanks for the help Geoffrey.


Last edit I swear

Between Geoffrey's help and a bit of "what does the example have that mine doesn't?" I was able to get it to work after a few steps:

1) Must generate a .XSL file to give structure to the .XML file. I used the plants.xsl file as a template.

2) in the event that sets my XmlDS object, I changed it to this:

if (tempData != String.Empty)
        {

            ChangeAccess.Style.Add("display", "block");
            XmlDS.DataFile = tempData;
            XmlDS.TransformFile = tempData.Remove(tempData.LastIndexOf('\\')) + "\\Permissions.xsl";
            Store1.DataSource = XmlDS;
            Store1.DataBind();
            File.Delete(tempData);
        } 

3) At this point, I knew it was loading the data as the Items were now displaying properly unfortunately the checkboxes weren't. So I made the function that generates my string/bool/bool/bool/bool/bool object list to replace the bool value with a 1 or a 0. So my xml was now 1 for a true value, for example. Works like a charm now.

Now onto the next step of pulling data from the Store when a button event is clicked to a XML file with duplicate structure.

Thanks again Geoffrey

Upvotes: 2

Views: 5601

Answers (1)

retype
retype

Reputation: 2385

You might need to post a code sample demonstrating the full scenario. You shouldn't have to call GridPanel1.Reload() on initial Page_Load.

The following example demonstrates binding an <asp:XmlDataSource> control to an <ext:Store>, see

http://examples.ext.net/#/GridPanel/DataSource_Controls/XmlDataSource/

Hope this helps.


EDIT: I did a little research and it appears the reason the .xslt is required is because the <asp:XmlDataSource> cannot/does-not parse the inner properties. The inner properties must be transformed to attributes.

The following sample demonstrates the full scenario using a .xml with properties configured as attributes and True|False converted to Lowercase true|false.

Example (.xml)

<?xml version="1.0" encoding="utf-8" ?>
<permissions>
    <permission Item="Process 1" Access1="true" Access2="true" Access3="false" Access4="false" Access5="true" />
    <permission Item="Process 2" Access1="true" Access2="true" Access3="true" Access4="false" Access5="false" />
    <permission Item="Process 3" Access1="false" Access2="true" Access3="false" Access4="false" Access5="true" />
    <permission Item="Process 4" Access1="true" Access2="true" Access3="false" Access4="false" Access5="false" />
    <permission Item="Process 5" Access1="true" Access2="false" Access3="false" Access4="false" Access5="true" />
    <permission Item="Process 6" Access1="true" Access2="false" Access3="true" Access4="false" Access5="true" />
</permissions>

Example (.aspx)

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>GridPanel with XmlDataSource - Ext.NET Examples</title>
    <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />

        <asp:XmlDataSource 
            ID="XmlDataSource1" 
            runat="server" 
            DataFile="sample.xml"
            />

        <ext:GridPanel 
            runat="server" 
            Width="650" 
            Height="300" 
            Title="Example"
            AutoExpandColumn="Item">
            <Store>
                <ext:Store runat="server" DataSourceID="XmlDataSource1">
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="Item" />
                                <ext:RecordField Name="Access1" Type="Boolean" />
                                <ext:RecordField Name="Access2" Type="Boolean" />
                                <ext:RecordField Name="Access3" Type="Boolean" />
                                <ext:RecordField Name="Access4" Type="Boolean" />
                                <ext:RecordField Name="Access5" Type="Boolean" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column ColumnID="Item" Header="Item" DataIndex="Item" />
                    <ext:Column Header="Access1" DataIndex="Access1" />
                    <ext:Column Header="Access2" DataIndex="Access2" />
                    <ext:Column Header="Access3" DataIndex="Access3" />
                    <ext:Column Header="Access4" DataIndex="Access4" />
                    <ext:Column Header="Access5" DataIndex="Access5" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>    
    </form>
</body>
</html>

Obviously you may not have control over the formatting of the .xml file, so converting with a .xslt provides a way to transform .xml file into a digestible format the <asp:XmlDataSource> can handle.

Upvotes: 1

Related Questions