Click here to Skip to main content
16,004,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everybody

i have xmlfile and i showen its in gridview

so how i can make ID column as hyperlink when i click any Id number its open new page and show me information in text box

this is my code

XML
<?xml version="1.0" standalone="yes"?>
<Students>
<Student>
<ID>1</ID>
<Name> ahmad </Name>
<Email> Ahmad@xml.com </Email>
<Address> Amman </Address>
<Mobile> 0781178778 </Mobile>
<Class> Seventh </Class>
</Student>
<Student>
<ID>2</ID>
<Name> Khaled </Name>
<Email> Khaled@xml.com </Email>
<Address> Zarqa </Address>
<Mobile> 078232342 </Mobile>
<Class> Sixth </Class>
</Student>
</Students>


and this is the first page(its called Default) html code

ASP.NET
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:GridView ID="GridView1" runat="server" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" CellPadding="0" 
        Width="1px">           
    </asp:GridView>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        Text="Add New Student" Width="118px" />

        </asp:Content>


and this is friest page behind code


C#
using System.Data;
using System.Xml;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet s = new DataSet();
        s.ReadXml(Server.MapPath("Courses.xml"));
        GridView1.DataSource= s.Tables[0];
        GridView1.DataBind();
       
        // Data Set dd = new Data Set();
        //dd.ReadXml("XML Path");
        //DataTable xm = ds.Tables[0];

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int gridrowscount = GridView1.Rows.Count;//getting grid view rows count to assign as id to the next 
        Response.Redirect("Default2.aspx?ID="+gridrowscount); // open new Page and transfering the count using querystring
        
               
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int gridrowscount = GridView1.Rows.Count;
        Response.Redirect("Default2.aspx?ID=");
    }
   
}


and this is second page (called Default2.aspx) behind code

C#
public partial class Default2 : System.Web.UI.Page
{
    int intID;// declaring global variable to ust it anywhere 
    string ID;
    protected void Page_Load(object sender, EventArgs e)
    {
        intID = int.Parse(Request.Params["ID"]) + 1;//to increase the int that coming from first page 1
        ID = intID.ToString();
        string s = Request.QueryString[0];

      
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
     
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet dsXML = new DataSet();
        dsXML.ReadXml(Server.MapPath("~/") + "Courses.xml");
        if (dsXML.Tables.Count > 0)
        {
            DataRow drstudent = dsXML.Tables[0].NewRow();
            drstudent["ID"] = Server.HtmlEncode(ID);
            drstudent["Name"] = Server.HtmlEncode(TextBox1.Text);
            drstudent["Email"] = Server.HtmlEncode(TextBox2.Text);
            drstudent["Address"] = Server.HtmlEncode(TextBox3.Text);
            drstudent["Mobile"] = Server.HtmlEncode(TextBox4.Text);
            drstudent["Class"] = Server.HtmlEncode(TextBox5.Text);

            dsXML.Tables[0].Rows.Add(drstudent);
        }

    
        dsXML.WriteXml(Server.MapPath("~/") + "Courses.xml");
        Response.Redirect("default.aspx");
       

    }

    private void BindData()
    {
        XmlTextReader xmlReader = new XmlTextReader(Server.MapPath("Courses.xml"));
        xmlReader.Close();
    }

}
Posted

1 solution

Have a look at the solutions posted to this question in CodeProject[^]
 
Share this answer
 

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