Results 1 to 12 of 12

Thread: [RESOLVED] Grd Small Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Resolved [RESOLVED] Grd Small Problem

    Code:
    <?xml version="1.0"?>
    <catalog>
       <book id="bk101">
          <author>Gambardella, Matthew</author>
               <price>44.95</price>
            </book>
       <book id="bk102">
          <author>Ralls, Kim</author>
               <price>5.95</price>
           </book>
       <book id="bk103">
          <author>A</author>
               <price>5.95</price>
            </book>
    <book id="bk104">
          <author>B</author>
               <price>5.95</price>
           </book>
       
    </catalog>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="true" > </asp:GridView>

    In o/p ,colums are shown in the order -
    author price id

    I have not set any order then y they are coming in the order
    author price id..Y not in id author price??
    Attached Images Attached Images  

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Grd Small Problem

    Scratch that. Eh this forum needs a delete.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3
    Hyperactive Member nepalbinod's Avatar
    Join Date
    Sep 2007
    Posts
    293

    Re: Grd Small Problem

    I find it hard to understand. Can you repost the question in simple English?

  4. #4
    Hyperactive Member dnanetwork's Avatar
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    349

    Re: Grd Small Problem

    how did u bind..i mean show me the code behind..@

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Grd Small Problem

    Hey Sean,

    PowerPosters can delete their own posts, and Moderators can delete anyone's posts. If you hit the red triangle in your post, and write a note explaining you would like the post deleted, a Moderator will come along and delete it for you.

    Gary

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Grd Small Problem

    Sonia,

    There must be more code than what you have shown. Can you provide more details.

    More instance, are you using an XmlDataSource to link the GridView to the xml file, or how are you connecting the two.

    Gary

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: Grd Small Problem

    Code:
    if (!IsPostBack)
            {
                          if (!IsPostBack)
                {
                    ds = new DataSet();
                    ds.ReadXml("C:\\Users\\indel_intern96\\Desktop\\SONIA FOLDER\\sonia1.xml");
                    GridView1 .DataSource = ds;
                    GridView1.DataBind();
                }
    
            }
    So sad,my thread is too bad,dat people want it to delete!!!

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Grd Small Problem

    Quote Originally Posted by sonia.sardana View Post
    So sad,my thread is too bad,dat people want it to delete!!!
    No, this isn't the case, Sean was talking about his post within your thread. He started typing something and then changed his mind, but isn't able to delete his post.

    Gary

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Grd Small Problem

    Hey,

    Because of the way that you are loading the XML, you don't have an "easy" way of re-ordering the columns. However, one way to do this would be the following:

    Code:
                    if (!IsPostBack)
                    {
                        DataSet ds = new DataSet();
                        ds.ReadXml(Server.MapPath("XMLFile1.xml"));
                        DataTable dt = ds.Tables[0];
                        dt.Columns["id"].SetOrdinal(0);
                        dt.Columns["author"].SetOrdinal(1);
                        dt.Columns["price"].SetOrdinal(2);
                        GridView1.DataSource = ds;
                        GridView1.DataBind();
                    }
    Hope that helps!!

    Gary

  10. #10
    Hyperactive Member dnanetwork's Avatar
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    349

    Re: Grd Small Problem

    gud one ...working great..

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: Grd Small Problem

    Thx gep sir very Much.
    Means If the XML file is in order
    id author price,its not necessary dat in dataset - columns are also in order id author price.Rite na??

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Grd Small Problem

    Hey,

    Yes. I don't know exactly how the DataSet.ReadXml orders the column, like you, I would have assumed the order in which they are defined in the XML, but that is clearly not the case. I suspect it is something to do with the fact that ID is actually an attribute on the book node, rather than a contained child node, like the other two, but that is a complete guess.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width