|
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.
|
|
|
|
|
|
|
Hey guys, am using a file uploader for a user to select a file,
But only the files in my working directory are allowed. If I
select a file outside my working directory i get an error saying:
the path of the file could not be found...I would to choose a file
from different directories
Does any know what i can do on this one?
Please help
|
|
|
|
|
Perhaps you don't have permission.
|
|
|
|
|
You need to give more information of your code, then any one can look on it
and tell you what is the problem.
|
|
|
|
|
Yes, we need detail description of your problem including code then
only we can help you in better manner.
Jinal Desai
|
|
|
|
|
Hey thanks guys for ya reps, well i wish i would xplain this better,
Here is a piece of code:
below 'files' is the name of my file uploader
HttpPostedFile myFile = files.PostedFile;
string strFilename = Path.GetFileName(myFile.FileName);
if (strFilename != "")
{
string[] lines = File.ReadAllLines(strFilename);
}
Reason: As anyone one else knows, when you choose browse on a file uploader, you can only select a file if it is present in the dialog box that opens.
So if I select a file in my working directory, it works ok but if i select a file 'Outside' my working directory then I receive the error above(file not found).
E.g my working directory is: C:\MyProject\SMS Send\contacts.txt this works
and if I choose: C:\Documents and Settings\Morgan\Desktop\testing.txt this will give a FileNotFound exception,
and when i look at this exception it is pointing to:C:\MyProject\SMS Send\testing.txt which is my working directory. I don't quiet understand why it is searching for the file from my working directory..
Please help
Thanks
Mor
|
|
|
|
|
You need to user Server.MapPath() while retrieving the full path.
e.g:
string strFilename = Server.MapPath(Path.GetFileName(myFile.FileName));//path of a file
I guess this should work now.
When you fail to plan, you are planning to fail.
|
|
|
|
|
Thanks for your reply man but hey this gives me the
same error(FileNotFound Exception)
I don't quiet know why...
|
|
|
|
|
Hi all,
What does the below code means?What exactly the secod line tells ...pls help me in this
Application.Lock();
an class="smallblack">Application[“mydata”]=”mydata”;
Application.UnLock();
Thanks In Advance
|
|
|
|
|
reogeo2008 wrote: an class="smallblack">Application[“mydata”]=”mydata”;
This line? It doesn't appear to be complete. But the portion it is showing is placing mydata into an application variable called mydata
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
asp.net program to generate search engine like google to search in the entire solution
Sameer Baig
|
|
|
|
|
You should ask specific doubts that you face/come across while working on something instead of asking full 'asp.net program' for something!
Perhaps you should use search engine google [^]for such queries!
|
|
|
|
|
Hai Sandeep,
Actually I got this requirement to implement in a project few days before.You are 100%
correct. Thankyou for your suggession .I will again search in
google and any doubts if I got then you are the best person to clarify it.
Cheers,
Sameer.
|
|
|
|
|
I am implementing url rewriting in my website by using urlrewriter.net(Intelligencia.UrlRewriter) and i am facing problem.
in my web.config i have written
<rewriter>
<rewrite url="~/Products/(.+)-(.+)" to="~/Products.aspx?CategoryName=$1&CategoryId=$2"/>
<rewrite url="~/Product/(.*)/(.*)" to="~/ProductDetails.aspx?ProductId=$2"/>
1) And my href for product is given as:
<li><a href='" & Page.ResolveUrl("~/Products/") & strUrl(notebooks-laptops)& "-" & intCategoryId(222) & "'>" & strMenu(notebooks & laptops) & "</a>
I am having the path now as
http://localhost/Products/notebooks-laptops/222 =>category and its id
but I want
http://localhost/Products/notebooks-laptops
but the search condition in application is through intCategoryId(222) so will require it.
2) In the above web.config code the second rewrite is for details of that product which is clicked.
my url is
http://localhost/Products/notebooks-laptops/345345435->ProductId
But its goes in both page products and productdetails page and finally in products and application get hanged.Is there is any mistake in rewriter code i.e rule in config file
PLease help me me for both the Probelm.Any help is appreciated
|
|
|
|
|
Hy ,
I have a very urgent requirement where i have a pdf file containg all the information in table format.
i have to trasfer it to database .HOw can i do it.
Is it possible to get the data in xlsheet so that i can transfer the data from xl sheet to database
|
|
|
|
|
you have to use converter...pdf to excel.
I know about this one.
1) smart-pdf-converter-pro (trial)
2) PDF to Excel 2.4
May this help you.
!- F - R - I - E - N - D - S -!
|
|
|
|
|
Hello Experts,
I tried the Print Button using remote option..
Print Button is Enabled,but i want that print should come on
Client Machine and not on server side...
Can U Please tell the other way i can use the print option on my report viewer control
M Using RDLC Report
Please Help
Thanks In Adv.
Sharing Of Knowledge Provides Solution....
|
|
|
|
|
|
Dear all,
I have a asp.net page to import some files from the local network and export them to other network locations or upload to ftp servers. the user can configure the import and export locations.
im using also impersonation with a network domain account to set the read/write permissions on the network machines for the page.
The webpage will be used most of the time locally on the webserver, or through lan.
so i can't use iis security settings because everybody who is logged in on the webserver can change the iis settings or the web.config file.
My question is how to secure the page in this situation?
Thanks in advance.
|
|
|
|
|
Priya Prk wrote: everybody who is logged in on the webserver can change the iis settings or the web.config file.
My question is how to secure the page in this situation?
Why would you allow users to change the web.config? How can a user change IIS setting? I think you have more problems with your design than just authentication.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark,
the website will be hosted by the user's company. they can reach it through the local network, but some of them can also log in into the webserver's(iis) pc, in this case they can change the iis or the web.config file. But i want at lease prevent them to use the webapplication.
|
|
|
|
|
You can't. If they have root access they undo any changes you make to the config or settings.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hai iam using ASP.NET C# to develop my project "LEAVE TRACKING SYSTEM"
my question is
**In leave apply page after selecting number of days throough text box and sanctioning authority, i press submit button. here i want to display one message box with the message box like " you are applying leave for 2 days to xxxauthority"
**please dont suggest alert or confirm box because they r showing values in other page that means the background is becoming white.
**i want to display message box on the page where i can able to see controls on UI page in disable mode.
i hope u will reply soon
regards
jyothi
|
|
|
|