Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need an alert message through java script validation .. i got correct output for the code given below . but i need an alert message if no data present in the xml file ..
C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Xml;
using System.Windows.Forms;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataColumn dc = new DataColumn("Name");
        DataColumn dc1 = new DataColumn("Date");
        DataColumn dc2 = new DataColumn("Address");
        dt.Columns.Add(dc);
        dt.Columns.Add(dc1);
        dt.Columns.Add(dc2);
        string ct = TextBox1.Text.ToString();
        //string ct = ddl.SelectedItem.ToString();
        string dataPath = Server.MapPath("formxml.xml");
        DataSet dSet = new DataSet();
        dSet.ReadXml(dataPath);
        DataRow[] rows = dSet.Tables[0].Select(" Date = '" + ct + "'");

        foreach (DataRow dr in rows)
        {
            DataRow myRow = dt.NewRow();
            myRow["Name"] = dr["Name"];

            myRow["Date"] = dr["Date"];
            myRow["Address"] = dr["Address"];
            dt.Rows.Add(myRow);       
        }
        grxml.DataSource = dt;
        grxml.DataBind(); 
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
    }
    protected void grxml_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
}
Posted
Updated 29-Jul-13 11:49am
v3
Comments
_Asif_ 26-Jul-13 3:21am    
could you please elaborate more!
Rajesh from Chennai 26-Jul-13 5:14am    
my problem is if data present in xml file means no problem but in this case of no appropiate data not present means an alert message must show through javascript
Rajesh from Chennai 26-Jul-13 5:16am    
in this line "DataRow[] rows = dSet.Tables[0].Select(" Date = '" + ct + "'");" i get the all date present in xml ..but if no data present in that date means i need a alert message through java script ....pls suggest me

1 solution

Please insert following lines after this peice of code

C#
DataRow[] rows = dSet.Tables[0].Select(" Date = '" + ct + "'");



C#
if (rows.count <= 0)
{
      StringBuilder cstext2 = new StringBuilder();
      cstext2.Append("<script type=\"text/javascript\">");
      cstext2.Append("alert('Data Not Found'};");
      cstext2.Append("</script>");
      RegisterClientScriptBlock(csname2, cstext2.ToString());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900