开发者

How update data by Javascript

How can I, on the OnChange event, update data in my database ? I have a WebMethod, that returns a HTML, so I can't see those elements, so I think he solution will be a javascript function.

A textarea catch the text from the database, if the user alter this, the database field has to be updated.

    [WebMethod]
    public static object ListAdvertise(string transaction)
    {
        StringBuilder retorno = new StringBuilder(160000);

        Utilidade.QuebraToken tk2 = new Utilidade.QuebraToken();
        string Credenciada = tk2.CarregaToken(1, HttpContext.Current.Request.Cookies["token"].Value);


        string select3 = "SELECT * FROM San_Imovel WHERE Status_Id = 1 AND Credenciada_Id = " + Credenciada + " AND Transacao_Id IN (" + transacao + ") ORDER BY NomeCidade, NomeBairro, Imovel_Id ASC";


        Utilidade.Conexao c3 = new Utilidade.Conexao();
        SqlConnection con3 = new SqlConnection(c3.Con);
        SqlCommand cmd3 = new SqlCommand(select3, con3);
        con3.Open();
        SqlDataReader r3 = cmd3.ExecuteReader();
        while (r3.Read())
        {
            Imovel_Id = r3["Imovel_Id"].ToString();
            Endereco = r3["Descricao"].ToString() + " " + r3["Logradouro"].ToString() + " " + r3["Numero"].ToString() + "/" + r3["DscComplemento"].ToString() + " " + r3["Complemento"].ToString() + " - " + r3["NomeBairro"].ToString();
            TextoAnuncio = r3["TextoAnuncio"].ToString();

            if (count % 2 == 0)
            {
                classe = "EstiloDalinhaGrid";
            }
            else
            {
                classe = "EstiloDalinhaA开发者_如何学JAVAlternativaGrid";
            }


            retorno.Append("<tr class='" + classe + "'>");
            retorno.Append("<td>");
            retorno.Append(Imovel_Id);
            retorno.Append("</td>");

            retorno.Append("<td>");
            retorno.Append(Endereco);
            retorno.Append("</td>");

            retorno.Append("<td>");
        retorno.Append("<textarea id='txtArea'>");
            retorno.Append(TextoAnuncio);
        retorno.Append("</textarea>");
            retorno.Append("</td>");

            retorno.Append("<td>");
            retorno.Append("<input type='checkbox' class='imoveisMarcados' id='" + Imovel_Id + "' />");
            retorno.Append("</td>");
            retorno.Append("</tr>");

            count++;
        }

        retorno.Append("</table>");
        con3.Close();

        return new
        {
            retorno = string.Format(retorno.ToString())
        };


i think you have to use Ajax for you to be able to update your data base .

check this link to learn more about ajax with Php (you chose whatever server side langage you'd like)

Ajax with PHP

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜