Click here to Skip to main content
14,974,182 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: session active and close the browser without login off... Pin
Parwej Ahamad17-Apr-10 1:13
professionalParwej Ahamad17-Apr-10 1:13 
AnswerRe: session active and close the browser without login off... Pin
Abhijit Jana17-Apr-10 2:39
professionalAbhijit Jana17-Apr-10 2:39 
Questionhow to access a label in gridview Pin
prasadbuddhika16-Apr-10 21:40
Memberprasadbuddhika16-Apr-10 21:40 
AnswerRe: how to access a label in gridview Pin
Brij16-Apr-10 21:52
mentorBrij16-Apr-10 21:52 
AnswerRe: how to access a label in gridview Pin
Abhijit Jana16-Apr-10 22:50
professionalAbhijit Jana16-Apr-10 22:50 
AnswerRe: how to access a label in gridview Pin
michaelschmitt19-Apr-10 0:33
Membermichaelschmitt19-Apr-10 0:33 
QuestionProblem with Dynamic data Pin
sarang_k16-Apr-10 20:41
Membersarang_k16-Apr-10 20:41 
QuestionDataset and XML Pin
Farraj16-Apr-10 7:05
MemberFarraj16-Apr-10 7:05 
Hello guys,
im trying to bind XML file into a Datagrid and editing it..

this is my XML file
<?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>


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>
                 <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 finaly 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);
        int w = Convert.ToInt32(e.Item.Attributes);


        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[3]["a"] = txtBoxProduct.Text;

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

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


        TextBox txtBoxAmount = (TextBox)e.Item.FindControl("txtBoxAmount");
        dataSet.Tables[0].Rows[3]["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();
    }
}



The error i get starts in this line of code

dataSet.Tables[0].Rows[row]["a"] = txtBoxProduct.Text;


I've been told that this could be a problem in the number of Tables of the dataset, according to my XML file i should create 2 tables in DATASET.

any help please?

thank you.
AnswerRe: Dataset and XML Pin
Estys18-Apr-10 0:27
MemberEstys18-Apr-10 0:27 
GeneralRe: Dataset and XML Pin
Farraj20-Apr-10 9:34
MemberFarraj20-Apr-10 9:34 
QuestionFile uploader Pin
Morgs Morgan16-Apr-10 4:32
MemberMorgs Morgan16-Apr-10 4:32 
AnswerRe: File uploader Pin
Priya Prk16-Apr-10 5:28
MemberPriya Prk16-Apr-10 5:28 
AnswerRe: File uploader Pin
Viral Upadhyay16-Apr-10 8:24
MemberViral Upadhyay16-Apr-10 8:24 
AnswerRe: File uploader Pin
Peace ON16-Apr-10 21:10
MemberPeace ON16-Apr-10 21:10 
GeneralRe: File uploader Pin
Morgs Morgan16-Apr-10 22:38
MemberMorgs Morgan16-Apr-10 22:38 
GeneralRe: File uploader Pin
www.Developerof.NET18-Apr-10 20:26
Memberwww.Developerof.NET18-Apr-10 20:26 
GeneralRe: File uploader Pin
Morgs Morgan18-Apr-10 21:57
MemberMorgs Morgan18-Apr-10 21:57 
Questionwhat does the the following C# code mean? an class="smallblack">Application[“mydata”]=”mydata”; Pin
reogeo200816-Apr-10 4:07
Memberreogeo200816-Apr-10 4:07 
AnswerRe: what does the the following C# code mean? an class="smallblack">Application[“mydata”]=”mydata”; Pin
Not Active16-Apr-10 4:15
mentorNot Active16-Apr-10 4:15 
Questionasp.net program to generate search engine like google Pin
sameer1a2b3c16-Apr-10 3:05
Membersameer1a2b3c16-Apr-10 3:05 
AnswerRe: asp.net program to generate search engine like google Pin
Sandeep Mewara17-Apr-10 3:28
mvaSandeep Mewara17-Apr-10 3:28 
GeneralRe: asp.net program to generate search engine like google Pin
sameer1a2b3c17-Apr-10 18:09
Membersameer1a2b3c17-Apr-10 18:09 
QuestionHAving problem in urlrewriter.net for the rediret page and for url Pin
Member 438775716-Apr-10 2:49
MemberMember 438775716-Apr-10 2:49 
Questionget the data of PDF to XL Sheet Pin
raghvendrapanda16-Apr-10 1:22
Memberraghvendrapanda16-Apr-10 1:22 
AnswerRe: get the data of PDF to XL Sheet Pin
adkalavadia16-Apr-10 23:22
Memberadkalavadia16-Apr-10 23:22 

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.