row_command

Discussion in '.NET' started by vinodkus@indiatimes.com, May 4, 2011.

  1. vinodkus@indiatimes.com

    vinodkus@indiatimes.com

    Joined:
    May 3, 2011
    Messages:
    2
    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();
    }
    }
     
    vinodkus@indiatimes.com, May 4, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page