473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XML Address Book in DataGrid

Hi,
I have been trying to create a set of web pages that reads an xml file
into a datagrid this I can do. Here is a sample of the code.

DataSet myDataSet = new DataSet();

myDataSet.ReadXml("Addrbook.xml");

dgBooks.DataSource = myDataSet;
dgBooks.DataBind();

<asp:datagrid id="dgBooks" runat="server"
AutoGenerateColumns="False"
AllowSorting="true" OnSortCommand="dgBooks_Sort"
AllowPaging="True" PageSize="25" PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="right" OnPageIndexChanged="dgBooks_NextPage">

<Columns>
<asp:HyperLinkColumn HeaderText="Name"
DataNavigateUrlField="fullName"
DataNavigateUrlFormatString="Details.aspx?id={0}" DataTextField="fullName"
Target="_self" />

<asp:BoundColumn HeaderText="E-mail Address" DataField="email" />
<asp:BoundColumn HeaderText="Comment" DataField="comment" />
</Columns>
</asp:datagrid>

I have also been able to get the paging of the data to work. Code as
follows.
protected void dgBooks_NextPage(Object sender,
DataGridPageChangedEventArgs e)
{
dgBooks.CurrentPageIndex = e.NewPageIndex;
dgBooks.DataBind();
}

I also want to be able to sort the data by different columns and I found a
sample for an sql datasource but it did not work on my xml data. Can
somebody show me a sample that works with the xml data.

Also I found a sample that shows how to make a link from the datagrid to a
new page. I got this to work as shown here.

<asp:HyperLinkColumn HeaderText="Name"
DataNavigateUrlField="fullName"
DataNavigateUrlFormatString="Details.aspx?id={0}" DataTextField="fullName"
Target="_self" />

I need to know how to display the one selected record in detail on the new
page. This was not shown in the example that I found. I would also like to
be able to edit the fields shown on the details page. A working sample would
be nice.

Thanks
Kenneth
Nov 18 '05 #1
3 2560
hi keeley,
use the following code to sort the datagrid in the method which handles
dgBooks.Sortcommand
Dim dv As DataView = New DataView(myDataset.tables(0))
dv.Sort = e.SortExpression;
dgBooks.DataSource = dv;
dgBooks.DataBind();

the best
srini

"Kenneth Keeley" wrote:
Hi,
I have been trying to create a set of web pages that reads an xml file


Nov 18 '05 #2
OK I have been able to get the table to sort the entries but I don't have
any column header buttons to change the sort option. If I remove the
AutoGenerateColumns="False" and the <Columns> section I do get the header
buttons but I also get all the unwanted columns of data that I what
displayed only on the view/edit details page.

"srini" <sr***@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
hi keeley,
use the following code to sort the datagrid in the method which handles
dgBooks.Sortcommand
Dim dv As DataView = New DataView(myDataset.tables(0))
dv.Sort = e.SortExpression;
dgBooks.DataSource = dv;
dgBooks.DataBind();

the best
srini

"Kenneth Keeley" wrote:
Hi,
I have been trying to create a set of web pages that reads an xml file

Nov 18 '05 #3
I have also found that the sort only works on the first page. The code I use
is below.

Code behind file.

public System.Web.UI.WebControls.DataGrid dgBooks;
public System.Web.UI.WebControls.Label Msg;
public string strSortBy = "";

public AddressBook_Default()
{
// Set the Page Title.
PageTitle = "Personal Address Book";
}

protected void Page_Load(object sender, EventArgs e)
{

if(!Page.IsPostBack)
{
if(strSortBy == "")
{
strSortBy = "fullname";
}

BindMe();
}

Msg.Text = "SortBy = " + strSortBy;
}

protected void BindMe()
{

DataSet myDataSet = new DataSet();

myDataSet.ReadXml("\\\\LVE004\\Mailboxes\\" + UserName +
"\\WC\\Addrbook.xml");
DataView dv = new DataView(myDataSet.Tables[0]);
dv.Sort = strSortBy;
dgBooks.DataSource = dv;

// dgBooks.DataSource = myDataSet;
dgBooks.DataBind();
}

protected void dgBooks_NextPage(Object sender,
DataGridPageChangedEventArgs e)
{
dgBooks.CurrentPageIndex = e.NewPageIndex;
BindMe();
// dgBooks.DataBind();
}

protected void dgBooks_Sort(object sender , DataGridSortCommandEventArgs
e)
{

// strSortBy = e.SortExpression;
BindMe();
// dgBooks.DataBind();
}
ASPX File
<asp:datagrid id="dgBooks" runat="server"
AutoGenerateColumns="false"
Font-Name="Verdana"
Font-Size="Small"
HorizontalAlign="Center"
ItemStyle-BackColor="#EAF1FC"
AlternatingItemStyle-BackColor="#D1E1FA"
Border="0"
AllowSorting="true" OnSortCommand="dgBooks_Sort"
AllowPaging="true" PageSize="25"
PagerStyle-Mode="NumericPages" PagerStyle-HorizontalAlign="right"
OnPageIndexChanged="dgBooks_NextPage">

<HeaderStyle BackColor="#5375E2" HorizontalAlign="Center"
ForeColor="White" Font-Bold="True" />

<Columns>
<asp:HyperLinkColumn HeaderText="Name"
DataNavigateUrlField="fullName"
DataNavigateUrlFormatString="Details.aspx?id={0}"
DataTextField="fullName"
Target="_self" />

<asp:BoundColumn HeaderText="E-mail Address" DataField="email" />
<asp:BoundColumn HeaderText="Comment" DataField="comment" />
</Columns>

</asp:datagrid>
</P>
<asp:Label id="Msg" runat="server"></asp:Label>

"srini" <sr***@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
hi keeley,
use the following code to sort the datagrid in the method which handles
dgBooks.Sortcommand
Dim dv As DataView = New DataView(myDataset.tables(0))
dv.Sort = e.SortExpression;
dgBooks.DataSource = dv;
dgBooks.DataBind();

the best
srini

"Kenneth Keeley" wrote:
Hi,
I have been trying to create a set of web pages that reads an xml file

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: truckmen | last post by:
Hello All, I still can't figure it all out. I am trying to create a web page (using php) where: 1) A visitor add his or her name to an address book that can also be viewed online by other...
5
by: Ignacio Domínguez | last post by:
Hi. Is there a way of accessing the address book, similar to what Outlook Express does, using C#? Thanks Ignacio Domínguez
5
by: John Smith Jr. | last post by:
Best ASP.NET C# book? I was thinking about O'Reilly Programming C# 2nd Edition.
0
by: Bob Avallone | last post by:
MetaPro Systems Inc. Visual Studio Dot Net Tips & Tricks #3 – Direct Access to Your Outlook Address Book. Project Type: VS.NET Windows Application Code Behind: Visual Basic I have a project...
2
by: OHM | last post by:
Windows Forms Controls. Has anyone personally read and recommends a good book which includes good coverage on DataGrids as this seems to be one of the most common problem areas. Regards - OHM
5
by: ttoboobz | last post by:
Help anyone... I'm creating a simple address book java program that would store 100 records. The GUI should be able to accept the name, address, phone no., and email add of a person by clicking a...
11
cjbrx3115
by: cjbrx3115 | last post by:
Hey guys- I just got this email from my friend. I'm not sure it will really work (it's a forward), so I'm askin' you people. Well, here it is: ...
1
by: Lpitt56 | last post by:
I am running MS Access 2007 and I want to update an Outlook Address book from my Access Database. I started out by importing the Outlook Address Book as a linked table and it linked fine. I then...
10
by: Mike Miller | last post by:
Hi, Am wanting to send email with php and need to access the global outlook address book. Are there any examples/tutorials on how to do this? M
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.