convert data ToSTRING
Ola, estou com um problema , tenho um formulario que contem um campo para inserir uma determinada data.
<asp:TextBox ID="TxtData" runat="server" BorderColor="Black" BorderWidth="1px" MaxLength="30"></asp:TextBox>
Só que o cliente esta pedindo para inserir caracteres neste mesmo campo e ele esta formatado para Data.ToString e eu nao estou conseguindo arrumar o script de inclusão para ele aceitar caracteres , alguem sabe como??? agradeço desde ja!!
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.IO;
using System.Text;
using System.Collections.Generic;
public partial class Agenda : System.Web.UI.Page
{
int cod_request; // Variável enviada via post com o código para deleção, e edição
String tipo_request; // Informa se é exclusão, edição, etc, valor 0 = edição, 1 = deleção, 2 inserção
ConexaoAgenda AgendaObj = new ConexaoAgenda();
ConexaoCursos CursosObj = new ConexaoCursos();
ConexaoPalestras PalestrasObj = new ConexaoPalestras();
ConexaoTreinamento TreinamentosObj = new ConexaoTreinamento();
List<AgendaItem> LstAgenda;
List<ConteudoCursoItem> LstCursos;
List<ConteudoPalestraItem> LstPalestras;
List<ConteudoTreinamentoItem> LstTreinamentos;
protected void Page_Load(object sender, EventArgs e){
// Carrega o DropDown com os links do site
LstCursos = CursosObj.SelecionaCurso(""); CursosObj.Fecha();
LstPalestras = PalestrasObj.SelecionaPalestra(""); PalestrasObj.Fecha();
LstTreinamentos = TreinamentosObj.SelecionaTreinamento(""); TreinamentosObj.Fecha();
int cod_conteudo;
// Carrega a lista de Cursos, cod = 0
cod_conteudo = 0;
for (int i = 0; i < LstCursos.Count; i++){
LstLinksInternos.Items.Add(new ListItem("Cursos: " + LstCursos[i].Titulo, "[http://www.institutoidep.com.br/html/conteudo.aspx?cod="](http://www.institutoidep.com.br/html/conteudo.aspx?cod=) + LstCursos[i].Cod + "&tipo=" + cod_conteudo));
}
// Carrega a lista de Palestras, cod = 1
cod_conteudo = 1;
for (int i = 0; i < LstPalestras.Count; i++){
LstLinksInternos.Items.Add(new ListItem("Palestras: " + LstPalestras[i].Titulo, "[http://www.institutoidep.com.br/html/conteudo.aspx?cod="](http://www.institutoidep.com.br/html/conteudo.aspx?cod=) + LstPalestras[i].Cod + "&tipo=" + cod_conteudo));
}
// Carrega a lista de Treinamentos, cod = 2
cod_conteudo = 2;
for (int i = 0; i < LstTreinamentos.Count; i++){
LstLinksInternos.Items.Add(new ListItem("Treinamentos: " + LstTreinamentos[i].Titulo, "[http://www.institutoidep.com.br/html/conteudo.aspx?cod="](http://www.institutoidep.com.br/html/conteudo.aspx?cod=) + LstTreinamentos[i].Cod + "&tipo=" + cod_conteudo));
}
LstAgenda = AgendaObj.SelecionaAgenda("");
if (Request.QueryString["cod"] != ""){
cod_request = Convert.ToInt32(Request.QueryString["cod"]); //Código do registro a ser alterado
}else{
cod_request = -1;
}
tipo_request = Request.QueryString["tipo"]; // Tipo de operção, edição ou deleção
if (!Convert.ToBoolean(Session["chave"]))
{ Response.Redirect("Default.aspx"); }
if (!Page.IsPostBack){
// Edição verifica se existe um cod de um item o e verifica o tipo de ação
if (cod_request != null){
//Edição
if (tipo_request == "0"){
for (int i = 0; i < LstAgenda.Count; i++){
AgendaItem ItemAg = LstAgenda[i];
if (ItemAg.Cod == cod_request){
//cidade,data,link_local,link_chegar,local,titulo
TxtCidade.Text = ItemAg.Cidade;
TxtData.Text = ItemAg.Data.ToString();
TxtDescricao.Text = ItemAg.Descricao;
LstLinksInternos.Items.FindByValue(ItemAg.LinkInterno).Selected = true;
TxtLinkComoChgar.Text = ItemAg.LinkComoChegar;
TxtLocal.Text = ItemAg.Local;
TxtTitulo.Text = ItemAg.Titulo;
break;
}
}
}else if (tipo_request == "1"){
// Deleção
try{
AgendaObj.Delete(cod_request);
Response.Redirect("agenda.aspx");
}catch{
string js = "<script>alert(' Registro Inexistente! ');</script>";
ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", js);
}
}
}
}
LblRegistros.Text = "";
// Carrega os registros no lado esquerdo da tela
for (int i = 0; i < LstAgenda.Count; i++){
AgendaItem ItemAg = LstAgenda[i];
LblRegistros.Text += "<div>";
LblRegistros.Text += "<div id='direito_item1'>-" + ItemAg.Titulo + "</div>";
LblRegistros.Text += "<div id='direito_item2'>" + ItemAg.Data.ToShortDateString() + "</div>";
LblRegistros.Text += "<div id='direito_item3'><a href='agenda.aspx?tipo=0&cod=" + ItemAg.Cod + "'>Editar</a>||<a href='agenda.aspx?tipo=1&cod=" + ItemAg.Cod + "'>Excluir</a></div>";
LblRegistros.Text += "</div>";
}
}
// Rotina para Adição/Edição de registro
protected void BtnGrava_Click(object sender, EventArgs e){
if (TxtTitulo.Text == "" || TxtData.Text == "" || TxtCidade.Text == "" || TxtLocal.Text == ""){
string js = "<script>alert(' Preencha todos os campos Obrigatórios: Título, Data, Cidade e Local! ');</script>";
ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", js);
}else{
AgendaItem ItemAg = new AgendaItem(cod_request, TxtTitulo.Text, Convert.ToDateTime(TxtData.Text), TxtCidade.Text, TxtLocal.Text, LstLinksInternos.SelectedValue.ToString(), TxtLinkComoChgar.Text, TxtDescricao.Text);
//Inserção
if (Request.QueryString["cod"] == null){
AgendaObj.Insere(ItemAg);
}else{ //UPdate
AgendaObj.Edita(ItemAg);
}
Response.Redirect("agenda.aspx");
}
}
}
e o erro:
>
The string was not recognized as a valid DateTime. There is a unknown word starting at index 9.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: The string was not recognized as a valid DateTime. There is a unknown word starting at index 9.
Source Error:
Line 121: ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", js);
Line 122: }else{
Line 123: AgendaItem ItemAg = new AgendaItem(cod_request, TxtTitulo.Text, Convert.ToDateTime(TxtData.Text), TxtCidade.Text, TxtLocal.Text, LstLinksInternos.SelectedValue.ToString(), TxtLinkComoChgar.Text, TxtDescricao.Text);
Line 124:
Line 125: //Inserção
Discussão (1)
Carregando comentários...