Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

My issue is that I need to change the column name(following format "Remove first character and after third character insert colon") of the gridview (which is bound with XMLTextReader), without directly changing the XML file. I am required to change the column name dynamically at runtime.

Performance.xml
XML
<Performance>
     <Departments>
            <Heading>FS</Heading>
            <S0015>1</S0015>
            <S0020>2</S0020>
            <S0025>5</S0025>
            <S0030>5</S0030>
            <S0035>6</S0035>
     </Departments>
     <Departments>
            <Heading>BS</Heading>
            <S0015>0</S0015>
            <S0020>3</S0020>
            <S0025>5</S0025>
            <S0030>1</S0030>
            <S0035>3</S0035>
       </Departments>
</Performance>

Heading   S0015   S0020   S0025   S0030   S0035
FS        1       2       4       5       6
BS        0       3       5       1       3

Required Format:"Remove first character and after third character insert colon"(S0015-- 00:15)


Heading   00:15   00:20   00:25   00:30   00:35
FS        1       2       4       5       6
BS        0       3       5       1       3

Kindly look on this issue.
Posted
Updated 13-Jan-11 23:54pm
v5
Comments
JF2015 14-Jan-11 4:47am    
Edited to fix code formatting.

Hi, I got how to change the column name, Can somebody help me out regarding changing the format ( Truncating first character and inserting colon after third character).

String Manipulation?

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            string x = e.Row.Cells.Count.ToString();
            int y = System.Int32.Parse(x);
            for (int i = 2; i < y; i++)
            {
                e.Row.Cells[i].Text = "xxx";

            }
        }
    }
 
Share this answer
 
v2
Use the Insert() function to put the colon in:
C#
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Insert(3,":");

Use the SubString() function to do the truncation:
C#
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Substring(1);

You can combine these two functions into a single statement:
C#
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Insert(2,":").Substring(1);
 
Share this answer
 
One way to do that is as follows:

C#
var bookquery = from k in XElement.Load(MapPath("book.xml")).Elements("book")
                join m in XElement.Load(MapPath("Library.xml")).Elements("Library")
                on (String)k.Element("bookid") equals (String)m.Element("bookid")
                select new bookclass
                {
                    bookid        = (String)m.Element"bookid"),
                    Title         = (String)k.Element("title"),
                    AuthorName    = (String)k.Element("author").Element("first-name"),
                    AuthorSurName = (String)k.Element("author").Element("last-name"),
                    Price         = (String)k.Element("price")
                };
GridView1.DataSource = bookquery;
GridView1.DataBind();
 
Share this answer
 
v2
Comments
manushi88 14-Jan-11 5:05am    
Could you please post in C#.Net.
#realJSOP 14-Jan-11 8:03am    
Your code block formatting was way off, so I fixed it.
YOGESH DHAGE 16-Jan-11 2:54am    
Thanks Friend............

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900