Friends I'm coming in php and starting to develop in C #. The differences are many ideas that I have when I will apply give errors such as the problem that I have a combobox html that dynamically filled with database data, I thought separates the code which would be the value of the combobox and put as a value in each position from an array up to that, but it does not work. The current version of the following error, does anyone have any idea how I solve?
Give this error:
"Object reference not set to an instance of an object."
Code;
using System;
using System.Configuration;
using System.Data;
using System.Net.Http;
using System.Text;
using System.Web;
using Newtonsoft.Json.Linq;
namespace empresa.UI.ProcessEmpresa
{
/// <summary>
/// Summary description for AjaxPrazoMedioCliente
/// </summary>
public class AjaxPrazoMedioCliente : IHttpHandler
{
string[] v;//CRIACAO DO VETOR
public int i, j = 0;
public void ProcessRequest(HttpContext context)
{
Grupo = Convert.ToString(context.Request.QueryString["codgrupo"]);
temmontante = Convert.ToString(context.Request.QueryString["temmontante"]);
selecionado = Convert.ToString(context.Request.QueryString["selecionado"]);
temmontante = temmontante.Equals("") ? "0" : temmontante;
HttpClient client = null;
string retorno = string.Empty;
if (client == null)
{
client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["url_servidor"]);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage resultado = client.GetAsync("xyz/Venda/PrazoMedio/" + Grupo + "/" + temmontante).Result;
retorno = resultado.Content.ReadAsStringAsync().Result;
if (resultado.StatusCode != System.Net.HttpStatusCode.NotFound)
{
if (retorno != "[]")
{
sb.Append("<select name=\"txtpagpedido\" id=\"txtpagpedido\" onchange=\"HabilitarDescontoPromocional()\" style=\"width: 200px;\" >");
sb.Append("<option value=\"0\">Selecione..</option>");
JArray usuarioarrray = JArray.Parse(retorno);
foreach (JObject obj in usuarioarrray.Children<JObject>())
{
foreach (JProperty prop in obj.Properties())
{
if (v[i] != null)//MEU TRECHO PESQUISEI QUE TALVEZ SOLUCIONARIA O ERRO
if (Convert.ToString(prop.Value) != v[i])
v[i] = prop.Value.ToString();
else
break;
//vetor[i] = Convert.ToString(prop.Value.ToString());
switch (prop.Name)
{
case "e4_CODIGO":
if (prop.Value.ToString().Equals(selecionado))
sb.Append("<option value=\"" + Convert.ToString(prop.Value.ToString()) + "\" selected=\"selected\" >");
else
sb.Append("<option value=\"" + Convert.ToString(prop.Value.ToString()) + "\" >");
break;
case "e4_DESCRI":
sb.Append(Convert.ToString(prop.Value.ToString()) + "</option>");
break;
default:
break;
}
i++;
}
}
sb.Append("</select>");
}
}
context.Response.Write(sb.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}