Click here to Skip to main content
14,541,903 members
   

XML / XSL

 
Questionbuilding an XML page Pin
Farraj13-Apr-10 5:26
MemberFarraj13-Apr-10 5:26 
AnswerRe: building an XML page Pin
Estys14-Apr-10 1:01
MemberEstys14-Apr-10 1:01 
GeneralRe: building an XML page Pin
Farraj14-Apr-10 1:20
MemberFarraj14-Apr-10 1:20 
GeneralRe: building an XML page Pin
Estys14-Apr-10 2:22
MemberEstys14-Apr-10 2:22 
GeneralRe: building an XML page Pin
Farraj14-Apr-10 6:07
MemberFarraj14-Apr-10 6:07 
GeneralRe: building an XML page Pin
Estys14-Apr-10 22:52
MemberEstys14-Apr-10 22:52 
GeneralRe: building an XML page Pin
Farraj15-Apr-10 0:46
MemberFarraj15-Apr-10 0:46 
AnswerRe: building an XML page Pin
Farraj16-Apr-10 4:26
MemberFarraj16-Apr-10 4:26 
Hi again Smile | :) thanks for your help with adding the XML data
i need to ask you another question
i've got my final xml file looking exactly as i need it to be

<?xml version="1.0" encoding="utf-8"?>
<chores>
  <day label="111" title="asdasd">
    <job a="2" b="22" c="22" d="22" />
    <job a="2" b="22" c="22" d="22" />
  </day>
</chores>


im trying to Edit this file in a dataGrid but its not working


my aspx page

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="EditTables.aspx.cs" Inherits="EditTables" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <table class="style1">
        <tr>
            <td>
                <br />
                <br />
                Edit your Products tables<br />
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True" 
                    AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" 
                    oncancelcommand="DataGrid1_CancelCommand" 
                    ondeletecommand="DataGrid1_DeleteCommand" oneditcommand="DataGrid1_EditCommand" 
                    onpageindexchanged="DataGrid1_PageIndexChanged" 
                    onupdatecommand="DataGrid1_UpdateCommand" AutoGenerateColumns="False" 
                    Width="890px">
                    <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                     <asp:TemplateColumn HeaderText=" label">
            <ItemTemplate>
              <%# DataBinder.Eval(Container.DataItem, "label")%>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox id="txtBoxTitle"
                   Text='<%# DataBinder.Eval(Container.DataItem, "label") %>'
                   runat="server" Height="21px" Width="80px"/>
            </EditItemTemplate>
          </asp:TemplateColumn>
          
          
           <asp:TemplateColumn HeaderText="title">
            <ItemTemplate>
              <%# DataBinder.Eval(Container.DataItem, "title")%>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox id="txtBoxTitle"
                   Text='<%# DataBinder.Eval(Container.DataItem, "title") %>'
                   runat="server" Height="21px" Width="80px"/>
            </EditItemTemplate>
          </asp:TemplateColumn>
          
      <asp:TemplateColumn HeaderText="כמות">
            <ItemTemplate>
              <%# DataBinder.Eval(Container.DataItem, "a")%>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox id="txtBoxAmount"
                   Text='<%# DataBinder.Eval(Container.DataItem, "a") %>'
                   runat="server" Height="21px" Width="80px"/>
            </EditItemTemplate>
          </asp:TemplateColumn>
          
           <asp:TemplateColumn HeaderText="מחירון">
            <ItemTemplate>
              <%# DataBinder.Eval(Container.DataItem, "b")%>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox id="txtBoxPrice"
                   Text='<%# DataBinder.Eval(Container.DataItem, "b") %>'
                   runat="server" Height="21px" Width="80px"/>
            </EditItemTemplate>
          </asp:TemplateColumn>
          
          
           <asp:TemplateColumn HeaderText="גודל">
            <ItemTemplate>
              <%# DataBinder.Eval(Container.DataItem, "c")%>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox id="txtBoxSize"
                   Text='<%# DataBinder.Eval(Container.DataItem, "c") %>'
                   runat="server" Height="22px" Width="80px"/>
            </EditItemTemplate>
          </asp:TemplateColumn>
          
          
           <asp:TemplateColumn HeaderText="מוצר">
            <ItemTemplate>
              <%# DataBinder.Eval(Container.DataItem, "d")%>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox id="txtBoxProduct"
                   Text='<%# DataBinder.Eval(Container.DataItem, "d") %>'
                   runat="server" Height="22px" Width="80px"/>
            </EditItemTemplate>
          </asp:TemplateColumn>
          
          
                        <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update">
                        </asp:EditCommandColumn>
                        <asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>
                    </Columns>
                    <EditItemStyle BackColor="#999999" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                </asp:DataGrid>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblerror" runat="server" ForeColor="Maroon"></asp:Label>
            </td>
        </tr>
    </table>
</asp:Content>



and this is my CS code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Globalization;
using System.IO;
using System.Data;
using System.Data.OleDb;

public partial class EditTables : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!User.IsInRole("Admin"))
     
           Server.Transfer("login.aspx");
        if (!(Page.IsPostBack))
        {
            DataGrid1.DataSource = LoadMyData();
            DataGrid1.DataBind();
        }

    }
    protected DataSet LoadMyData()
    {
        string sourceXml = Server.MapPath("~/xml/chores2.xml");
        if (!(File.Exists(sourceXml)))
        {
            return null;
        }
        DataSet cachedDataSet = (DataSet)Session["table"];
        if (!(cachedDataSet == null))
        {
            return cachedDataSet;
        }
        DataSet dataSet = new DataSet();
        try
        {
            dataSet.ReadXml(sourceXml);
            Session["table"] = dataSet;
        }
        catch (Exception e)
        {
            lblerror.Text = e.Message;
            dataSet = null;
        }
        return dataSet;
    }
    protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
    {

        DataGrid1.EditItemIndex = Convert.ToInt32(e.Item.ItemIndex);
        DataGrid1.DataSource = LoadMyData();

        DataGrid1.DataBind();
    }
    protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
    {
        DataGrid1.EditItemIndex = -1;
        DataGrid1.DataSource = LoadMyData();
        DataGrid1.DataBind();
    }
    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
    {
        DataSet dataSet = LoadMyData();
        int row = Convert.ToInt32(e.Item.ItemIndex);
        dataSet.Tables[0].Rows[row].Delete();
        dataSet.WriteXml(Server.MapPath("~/XML/chores2.xml"));
        Session["table"] = null;
        DataGrid1.EditItemIndex = -1;
        DataGrid1.DataSource = LoadMyData();
        DataGrid1.DataBind();
    }
    protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
    {
        DataSet dataSet = LoadMyData();
        int row = Convert.ToInt32(e.Item.ItemIndex);

        TextBox txtBoxLabel = (TextBox)e.Item.FindControl("txtBoxLabel");
        dataSet.Tables[0].Rows[row]["label"] = txtBoxLabel.Text;

        TextBox txtBoxTitle = (TextBox)e.Item.FindControl("txtBoxTitle");
        dataSet.Tables[0].Rows[row]["title"] = txtBoxTitle.Text;

        TextBox txtBoxProduct = (TextBox)e.Item.FindControl("txtBoxProduct");
        dataSet.Tables[0].Rows[row]["a"] = txtBoxProduct.Text;

        TextBox txtBoxSize = (TextBox)e.Item.FindControl("txtBoxSize");
        dataSet.Tables[0].Rows[row]["b"] = txtBoxSize.Text;

        TextBox txtBoxPrice = (TextBox)e.Item.FindControl("txtBoxPrice");
        dataSet.Tables[0].Rows[row]["c"] = txtBoxPrice.Text;


        TextBox txtBoxAmount = (TextBox)e.Item.FindControl("txtBoxAmount");
        dataSet.Tables[0].Rows[row]["d"] = txtBoxAmount.Text;



    

        dataSet.WriteXml(Server.MapPath("~/XML/chores2.xml"));
        Session["table"] = null;
        DataGrid1.EditItemIndex = -1;
        DataGrid1.DataSource = LoadMyData();
        DataGrid1.DataBind();
    }
    protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
        DataGrid1.DataSource = LoadMyData();
        DataGrid1.DataBind();
    }
}


it keeps telling me whenever i load the page
DataBinding: 'System.Data.DataRowView' does not contain a property with the name a..

anyway the problem is here..
dataSet.Tables[0].Rows[row]["a"] = txtBoxProduct.Text;

i guess this line is not working for the xml attributes
int row = Convert.ToInt32(e.Item.ItemIndex);

how can i fix that to work with my xml?
GeneralRe: building an XML page Pin
Estys16-Apr-10 6:04
MemberEstys16-Apr-10 6:04 
GeneralRe: building an XML page Pin
Farraj24-Apr-10 9:46
MemberFarraj24-Apr-10 9:46 
QuestionImage in XML Pin
farokhian10-Apr-10 5:08
Memberfarokhian10-Apr-10 5:08 
AnswerRe: Image in XML Pin
daveyerwin10-Apr-10 10:29
Memberdaveyerwin10-Apr-10 10:29 
Questionhey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
anubir7-Apr-10 9:44
Memberanubir7-Apr-10 9:44 
AnswerRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
Stuart Dootson7-Apr-10 14:22
professionalStuart Dootson7-Apr-10 14:22 
GeneralRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
anubir8-Apr-10 3:07
Memberanubir8-Apr-10 3:07 
GeneralRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
anubir8-Apr-10 3:08
Memberanubir8-Apr-10 3:08 
GeneralRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
Stuart Dootson8-Apr-10 4:49
professionalStuart Dootson8-Apr-10 4:49 
QuestionXML File is not updated in IE browser Pin
vdtrip7-Apr-10 8:40
Membervdtrip7-Apr-10 8:40 
QuestionGenerating a new XML file starting with a XML file and applyng XSLT Pin
FJJCENTU5-Apr-10 7:32
MemberFJJCENTU5-Apr-10 7:32 
AnswerRe: Generating a new XML file starting with a XML file and applyng XSLT Pin
FJJCENTU5-Apr-10 8:56
MemberFJJCENTU5-Apr-10 8:56 
QuestionCompiling an XML database with an application Pin
brdavid24-Mar-10 21:19
Memberbrdavid24-Mar-10 21:19 
AnswerRe: Compiling an XML database with an application Pin
Stuart Dootson28-Mar-10 21:46
professionalStuart Dootson28-Mar-10 21:46 
QuestionHow can i read or get an XML from another host? Pin
spawneditions24-Mar-10 8:58
Memberspawneditions24-Mar-10 8:58 
AnswerRe: How can i read or get an XML from another host? Pin
daveyerwin25-Mar-10 6:33
Memberdaveyerwin25-Mar-10 6:33 
QuestionXSLT help Pin
Aljaz11124-Mar-10 4:39
MemberAljaz11124-Mar-10 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.