I have a GridView with some columns. If exist a value in my database, a cell in my gridview has to updated his own value.
For example:
1 2
1 - Lucas Delete
2 - Drake Delete
3 - Jimmy Update/Delete
If Jimmy exists in my DataBase, then I have to put the “Update/Delete” in my second column, but if this “Update” label is clicked, I call a javascript. How can I do that ? It can be done via Sql ?
My code-behind:
protected void carregaGrid()
{
Utilidade.QuebraToken tk = new Utilidade.QuebraToken();
string Credenciada = tk.CarregaToken(1, Request.Cookies["token"].Value);
string Proposta = string.Empty;
string select = string.Empty;
select = "SELECT San_Proposta.Proposta_Id, San_Proposta.DataHora, San_Proposta.ValorProposta, San_Proposta.Comentario, "
+ "San_Usuario.NomeCompleto, San_Credenciada.Apelido, San_StatusProposta.Descricao, "
+ "(SELECT COUNT(*) "
+ "FROM San_PropostaConversa "
+ "WHERE San_PropostaConversa.Proposta_Id = San_Proposta.Proposta_Id "
+ "AND San_PropostaConversa.Credenciada_Id = San_Proposta.Credenciada_Id) as Numero "
+ "FROM San_Proposta "
+ "JOIN San_Credenciada "
+ "ON San_Proposta.Credenciada_Id = San_Credenciada.Credenciada_Id "
+ "JOIN San_StatusProposta "
+ "ON San_Proposta.StatusProposta_Id = San_StatusProposta.StatusProposta_Id "
+ "JOIN San_Usuario "
+ "ON San_Proposta.Usuario_Id = San_Usuario.Usuario_Id ";
if (Request.QueryString["Imovel_Id"].ToString() != string.Empty)
{
string imovel = Request.QueryString["Imovel_Id"].ToString();
select += "WHERE San_Proposta.Imovel_Id = " + imovel + " "
+ "AND San_Proposta.Credenciada_Id = " + Credenciada + " "
+ "AND San_Proposta.StatusProposta_Id IN (1,2) ";
}
}
select += "ORDER BY San_Proposta.DataHora DESC, Apelido ";
neticonn.Conexao c = new neticonn.Conexao();
dsGrid.ConnectionString = c.Con;
dsGrid.SelectCommand = select;
}
You have to use an ajax request to check if your item exists in your database. Your script will return you a json with true if your request finds it, false otherwise.
The other way is to build a javascript array on your page loading and check on it if your value is present.
I don’t know c#, but in php it will do something like :
It will make you a javascript array looking like :
You just have to loop on this array to check if an element exists or use a javascript function to do that.