row_command

Joined
May 3, 2011
Messages
2
Reaction score
0
Hi Friends,

I have written code to insert data at rowcommand. I checked its command name and insert record. In c# it is going right. but in vb.net it is inserting record two times because same code is fire two times. I am using xml.

code in vb.net
If e.CommandName = "AddNewPlan" Then
strPlanId = DirectCast(GridView1.FooterRow.FindControl("ddlNewPlan"), DropDownList).SelectedValue.Split("$"c)(0).ToString()
strPlanName = DirectCast(GridView1.FooterRow.FindControl("ddlNewPlan"), DropDownList).SelectedItem.Text
strPlanDuration = DirectCast(GridView1.FooterRow.FindControl("lblNewPlanDuration"), Label).Text
strPlanPrice = DirectCast(GridView1.FooterRow.FindControl("lblNewInrPrice"), Label).Text
strPlanQnt = DirectCast(GridView1.FooterRow.FindControl("txtNewQnt"), TextBox).Text
strPlanAmt = DirectCast(GridView1.FooterRow.FindControl("txtNewAmt"), TextBox).Text
xmlDoc = New XmlDocument()
If File.Exists(Server.MapPath("AddPlan.xml")) Then
xmlDoc.Load(Server.MapPath("AddPlan.xml"))
Dim elmXml As XmlElement = xmlDoc.CreateElement("Plans")
strNewPlan = "<PlanId>" & strPlanId & "</PlanId>"
strNewPlan += "<PlanName>" & strPlanName.Replace("&", "&amp;") & "</PlanName>"
strNewPlan += "<PlanDuration>" & strPlanDuration & "</PlanDuration>"
strNewPlan += "<INRPrice>" & strPlanPrice & "</INRPrice>"
strNewPlan += "<Quantity>" & strPlanQnt & "</Quantity>"
strNewPlan += "<Amount>" & strPlanAmt & "</Amount>"
elmXml.InnerXml = strNewPlan
xmlDoc.DocumentElement.AppendChild(elmXml)
xmlDoc.Save(Server.MapPath("AddPlan.xml"))
BindFromNewXML()
End If
End If

code in c#
if (e.CommandName == "AddNewPlan")
{
strPlanId = ((DropDownList)GridView1.FooterRow.FindControl("ddlNewPlan")).SelectedValue.Split('$')[0].ToString();
strPlanName = ((DropDownList)GridView1.FooterRow.FindControl("ddlNewPlan")).SelectedItem.Text;
strPlanDuration = ((Label)GridView1.FooterRow.FindControl("lblNewPlanDuration")).Text;
strPlanPrice = ((Label)GridView1.FooterRow.FindControl("lblNewInrPrice")).Text;
strPlanQnt = ((TextBox)GridView1.FooterRow.FindControl("txtNewQnt")).Text;
strPlanAmt = ((TextBox)GridView1.FooterRow.FindControl("txtNewAmt")).Text;
xmlDoc = new XmlDocument();
if (File.Exists(Server.MapPath("AddPlan.xml")))
{
xmlDoc.Load(Server.MapPath("AddPlan.xml"));
XmlElement elmXml = xmlDoc.CreateElement("Plans");
strNewPlan = "<PlanId>" + strPlanId + "</PlanId>";
strNewPlan += "<PlanName>" + strPlanName.Replace("&","&amp;") + "</PlanName>";
strNewPlan += "<PlanDuration>" + strPlanDuration + "</PlanDuration>";
strNewPlan += "<INRPrice>" + strPlanPrice + "</INRPrice>";
strNewPlan += "<Quantity>" + strPlanQnt + "</Quantity>";
strNewPlan += "<Amount>" + strPlanAmt + "</Amount>";
elmXml.InnerXml = strNewPlan;
xmlDoc.DocumentElement.AppendChild(elmXml);
xmlDoc.Save(Server.MapPath("AddPlan.xml"));
BindFromNewXML();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top