Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

webmethod, aspx, c#

I have the webmethod below and it works fine.
Now, I need to add database bind  because I have gridview inside of this page. In this case, what can i do?

 [WebMethod]
        public static string RemoveXMLData(int messageID)
        {
            string result = "";
            try
            {
                string templatePath = HttpContext.Current.Request.PhysicalApplicationPath + "UserMessages.xml";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(templatePath);
                try
                {
                    XmlNodeList nodeList = xmlDoc.SelectNodes("Users/User[MessageID = " + messageID + "]");

                    foreach (XmlNode xn in nodeList)
                    {
                        xn.ParentNode.RemoveChild(xn);
                    }                   
                    result = "Data deleted";                    
                }
                catch { result = "Some error in node deletion"; }
                finally
                {
                    xmlDoc.Save(templatePath);
                }
            }
            catch { result = "Eror in xml file loading"; }
            return result;
        }

     html = html + "<ul class='list-unstyled'>" +
                                          "<li class='left clearfix'>" +
                                          "<span class='chat-img1 pull-left' style='vertical-align: text-top;'>" +
                                          "<i class='fa fa-user-plus fa-2x' style='float:left;color:green;' aria-hidden=;true'></i>" +
                                          "</span>" +
                                          "<div class='chat-body1 clearfix'>" +
                                          "<p>" + this.From +
                                          "&nbsp;&nbsp;<input type='button' value='Mark as Read' class='btn btn-primary btn-xs' onclick='RemoveXMLData(\"" + this.MessageID + "\")'></button>" +
                                          "</br></br>" + "<i style='width:300px;word-wrap: break-word;color=red;'>" + this.MessageBody + "</i>" + "</p>" +
                                          "<div class='chat_time pull-right'><i>" + this.MesssageCreateDateTime + "</i></div>" +
                                          "</div>" +
                                          "</li>" +
                                          "</ul>";

Open in new window

Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Are you asking how to bind the results of your webmethod to a gridview?  If not, please clarify what you mean by "database bind".
Avatar of ITsolutionWizard

ASKER

Like below:

public static string RemoveXMLData(int messageID)
        {
 // databind()          
}
anyone can help?
What datasource are you trying to bind?  The content of XmlDoc ?  Or ?
database.
actually not database. xml
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It won't work inside of web method
Ah, ok.
You can't bind to a control inside of a webmethod.