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
first page >
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
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();
//System.Xml.XmlDocument myXml = new System.Xml.XmlDocument();
//myXml.Load(Server.MapPath("Courses.xml"));
//System.Xml.XmlNode xmlNode = myXml.DocumentElement.LastChild;//must be lastchild not first child
//System.Xml.XmlElement xmlElement = myXml.CreateElement("Students");// here we must use insertafter not creat element so try it
//xmlElement.SetAttribute("ID", Server.HtmlEncode(ID)); //inserting into xml file the id
//xmlElement.SetAttribute("Name", Server.HtmlEncode(TextBox1.Text));
//xmlElement.SetAttribute("Email", Server.HtmlEncode(TextBox2.Text));
//xmlElement.SetAttribute("Address", Server.HtmlEncode(TextBox3.Text));
//xmlElement.SetAttribute("Mobile", Server.HtmlEncode(TextBox4.Text));
//xmlElement.SetAttribute("Class", Server.HtmlEncode(TextBox5.Text));
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];
}
Second 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();
//due to the ID To query the related data
//give textbox control to set value
//txtname.Text='...';
//txtclass.Text='...';
}
Hope it helps you.
We are trying to better understand customer views on social support experience. Click HERE to participate the survey. Thanks!
None
0 Points
8 Posts
Xml Gridview c#.net
Nov 14, 2013 02:20 AM|ahmad_hammad|LINK
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
first page >
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)
{
}
}
Second Page >>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
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();
}
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);
}
//System.Xml.XmlDocument myXml = new System.Xml.XmlDocument();
//myXml.Load(Server.MapPath("Courses.xml"));
//System.Xml.XmlNode xmlNode = myXml.DocumentElement.LastChild;//must be lastchild not first child
//System.Xml.XmlElement xmlElement = myXml.CreateElement("Students");// here we must use insertafter not creat element so try it
//xmlElement.SetAttribute("ID", Server.HtmlEncode(ID)); //inserting into xml file the id
//xmlElement.SetAttribute("Name", Server.HtmlEncode(TextBox1.Text));
//xmlElement.SetAttribute("Email", Server.HtmlEncode(TextBox2.Text));
//xmlElement.SetAttribute("Address", Server.HtmlEncode(TextBox3.Text));
//xmlElement.SetAttribute("Mobile", Server.HtmlEncode(TextBox4.Text));
//xmlElement.SetAttribute("Class", Server.HtmlEncode(TextBox5.Text));
//myXml.DocumentElement.InsertBefore(xmlElement, xmlNode);
//myXml.Save(Server.MapPath("Courses.xml"));
//BindData();
dsXML.WriteXml(Server.MapPath("~/") + "Courses.xml");
Response.Redirect("default.aspx");
//TextBox1.Text = "";
//TextBox2.Text = "";
//TextBox3.Text = "";
//TextBox4.Text = "";
//TextBox5.Text = "";
}
private void BindData()
{
XmlTextReader xmlReader = new XmlTextReader(Server.MapPath("Courses.xml"));
xmlReader.Close();
}
}
xml file >>
<?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>
<Student>
<ID>3</ID>
<Name> Hammad</Name>
<Email> Hammad@xml.com </Email>
<Address> Irbed </Address>
<Mobile> 0782323332 </Mobile>
<Class> FOurth </Class>
</Student>
<Student>
<ID>4</ID>
<Name> Iyad </Name>
<Email> Iyad@xml.com </Email>
<Address> Zarqa </Address>
<Mobile> 079099992 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>5</ID>
<Name> Mryam </Name>
<Email> Mryam@xml.com </Email>
<Address> Amman </Address>
<Mobile> 078234333 </Mobile>
<Class> Fourth </Class>
</Student>
<Student>
<ID>6</ID>
<Name> Len </Name>
<Email> Len@xml.com </Email>
<Address> Zarqa </Address>
<Mobile> 07823222 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>7</ID>
<Name> Lamya </Name>
<Email> Lamya@xml.com </Email>
<Address> Irbed </Address>
<Mobile> 0782323232 </Mobile>
<Class> Fouth </Class>
</Student>
<Student>
<ID>8</ID>
<Name> Yasser </Name>
<Email> Yasser@xml.com </Email>
<Address> Zarqa </Address>
<Mobile> 0782989899 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>9</ID>
<Name> Fayha </Name>
<Email> Fayha@xml.com </Email>
<Address> Amman </Address>
<Mobile> 078888888 </Mobile>
<Class> Fourth </Class>
</Student>
<Student>
<ID>10</ID>
<Name> Hayfa </Name>
<Email> Hayfa@xml.com </Email>
<Address> Amman </Address>
<Mobile> 079999999 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>11</ID>
<Name> Ayman </Name>
<Email> Ayman@xml.com </Email>
<Address> Zarqa </Address>
<Mobile> 079999099 </Mobile>
<Class> Fourth </Class>
</Student>
<Student>
<ID>12</ID>
<Name> Shady </Name>
<Email> Shady@xml.com </Email>
<Address> Amman </Address>
<Mobile> 079993343 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>13</ID>
<Name> Odai </Name>
<Email> Odai@xml.com </Email>
<Address> Irbed </Address>
<Mobile> 079923232 </Mobile>
<Class> Fourth </Class>
</Student>
<Student>
<ID>14</ID>
<Name> Qusay </Name>
<Email> Qusay@xml.com </Email>
<Address> Amman </Address>
<Mobile> 0791212121 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>15</ID>
<Name> Majd </Name>
<Email> Majd@xml.com </Email>
<Address> Amman </Address>
<Mobile> 0772122211 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>16</ID>
<Name> Shaden </Name>
<Email> Shaden@xml.com </Email>
<Address> Irbed </Address>
<Mobile> 07996766657 </Mobile>
<Class> Fourth </Class>
</Student>
<Student>
<ID>17</ID>
<Name> Yassmen </Name>
<Email> Yassmen@xml.com </Email>
<Address> Amman </Address>
<Mobile> 07755616287 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>18</ID>
<Name> Nsreen </Name>
<Email> Nsreen@xml.com </Email>
<Address> Amman </Address>
<Mobile> 079122999 </Mobile>
<Class> Fourth </Class>
</Student>
<Student>
<ID>19</ID>
<Name> Sammer </Name>
<Email> Sammer@xml.com </Email>
<Address> Amman </Address>
<Mobile> 07993323 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>20</ID>
<Name> Israa </Name>
<Email> Israa@xml.com </Email>
<Address> Zarqa </Address>
<Mobile> 0798888888 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>21</ID>
<Name> Israa </Name>
<Email> Israa@xml.com </Email>
<Address> Zarqa </Address>
<Mobile> 0798888888 </Mobile>
<Class> Sixth </Class>
</Student>
<Student>
<ID>22</ID>
<Name>qwe</Name>
<Email>qwe</Email>
<Address>qwe</Address>
<Mobile>wqe</Mobile>
<Class>qwe</Class>
</Student>
<Student>
<ID>23</ID>
<Name>asda</Name>
<Email>qwd</Email>
<Address>da</Address>
<Mobile>dasd</Mobile>
<Class>sad</Class>
</Student>
</Students>
All-Star
15648 Points
2151 Posts
Re: Xml Gridview c#.net
Nov 15, 2013 01:23 AM|Happy Chen - MSFT|LINK
hi ahmad_hammad ,
i would suggest you try the demo :
Code-Behind:
Second Page >>
Hope it helps you.
None
0 Points
8 Posts
Re: Xml Gridview c#.net
Nov 16, 2013 07:04 AM|ahmad_hammad|LINK
Hello Happy chen
thank u alot
but its not work >> i want make the same id column as hyperlink >> not genarete new column >
All-Star
15648 Points
2151 Posts
Re: Xml Gridview c#.net
Nov 18, 2013 09:36 PM|Happy Chen - MSFT|LINK
I couldn't understand your question below:
Please explain what you are trying to do in detail,Can you post the complete markup or provide a simple demo which can easily reproduce the problem ?
In order to help us to understand your issue better. Thanks.