feedback system using xmldatasource. Help on gridview..

Posted by A4u6178 under Regular Expressions on 6/18/2011 | Points: 10 | Views : 1144 | Status : [Member] | Replies : 5
Hi all ,
i want to create feedback system where em using textboxes to capture name, emailid, cnt number, description like fields.
now i want these values to be entered into xml file and a gridview is been bind to this xml file so that i can view the sent messages.
my codes..
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile2.xml" XPath="/gridview/message">
</asp:XmlDataSource>

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds1 = new DataSet();
ds1.ReadXml(Server.MapPath("XMLFile2.xml"));
GridView1.DataSource = ds1;
GridView1.DataBind();

}

protected void btnSend_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\Users\anil\Documents\Visual Studio 2010\WebSites\WebSite12\XMLFile2.xml");
XmlElement root = doc.CreateElement("Message");
XmlElement FirstName = doc.CreateElement("FirstName");
XmlElement EmailID = doc.CreateElement("EmailID");
XmlElement ContactNumber = doc.CreateElement("ContactNumber");
XmlElement Description = doc.CreateElement("Description");
FirstName.InnerText = txtName.Text;
EmailID.InnerText = txtEmailID.Text;
ContactNumber.InnerText = txtCntNum.Text;
Description.InnerText = txtMessage.Text;
root.AppendChild(FirstName);
root.AppendChild(EmailID);
root.AppendChild(ContactNumber);
root.AppendChild(Description);
doc.DocumentElement.AppendChild(root);
doc.Save(@"C:\Users\anil\Documents\Visual Studio 2010\WebSites\WebSite12\XMLFile2.xml");
txtName.Text = "";
txtEmailID.Text ="";
txtCntNum.Text ="" ;
txtMessage.Text = "";

}
}


Thanks & Regards;
aaa



Responses

Posted by: SheoNarayan on: 6/18/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
What is the problem you are facing? The above code is not working, if not where it is not working?

Regards,
Sheo Narayan
http://www.dotnetfunda.com

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/18/2011 [Member] Starter | Points: 25

Up
0
Down
Hi sir ,
Thanks for ur reply.
The code i have pasted works well as entering the values of textboxes into xml file is cocerned , but i want to display the xml file data into a gridview. The PROBLEM is gridview is not updating dynamically when i enter values into xml file from textboxes.

Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/19/2011 [Member] Starter | Points: 25

Up
0
Down
Try to bind the grid after save/send button is clicked.
Thanks,
Debata

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hello sir,
I tried to bind the gridview in the btnSend_Click also but still em not able to get the entered values into xml from the textboxes in the gridview.

Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Take a look at the attached sample.
Please feel free to modify it.

 Download source file

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response