Tuesday, 28 October 2014

how to work with asp.net chart control using c#

hai..friend today i am going to explain how to work with asp.net chart control using c# ..

By using chart control we can display data in dynamic way Which is present in database.

Step 1 :By I Had created database with following tables :





Step 2 :I have enter the field with following data :





Step 3: Now i haven RegisterPage.aspx  & used grid view control to display the database data..







Step 4:Now i have taken Chart Control To display the data in dynamically that is in the form column,pie,stock,Area,Bubble,bar And Many more....

Drag and Drop chart control in aspx Page ..you will get the following code





Chat is displayed in the following Way
       



Choose Data Source For chart Control  From Sql Database Click Next


Next Connect To New Connection -->Connect to the database using database mode connection

you will get the picture Click On Next For save connection String Name as "myworldConnectionString2".


 Next Step:

In this Step I will check weather to choose all the field in the table or  any one...In my project I select All the Feilds using * in the Picture Click Next On it The query will be Displayed  


Next Step:
Test The Query ,You will Find the Output  from the database table records..click On Finish











Next Step:


 











Friday, 10 October 2014

DropDownList with country, state and city in ASP. NET,Country State City Cascading Dropdownlist in Asp.net

Hai friend today i am going to explain about DropDownList with country, state and city in ASP. NET
when user  selected country from on countries list  based on country all related states should be  bind to the dropdown & when the user select state from the state's list the user must get all region from region list .here we use a property as Auto Postback="True" for every Dropdown






<body style="background-image: url('colorful_background-wide.jpg'); height: 247px;">
    <form id="form1" runat="server">
    <div align="center">
   
    <table>
    <tr>
    <td>Select Country</td>
    <td>:</td>
  
    <td>      
     <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"
             >
       
        <asp:ListItem>Select</asp:ListItem>
  
        </asp:DropDownList>

 </td>   </tr>
   <tr>
    <td>Select State</td>
    <td>:</td>
  
    <td>        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
            onselectedindexchanged="DropDownList2_SelectedIndexChanged">
        <asp:ListItem>Select</asp:ListItem>
        </asp:DropDownList>
 </td>   </tr>
   <tr>
    <td>Select region</td>
    <td>:</td>
   
    <td>        <asp:DropDownList ID="DropDownList3" runat="server">
        <asp:ListItem>Select</asp:ListItem>
        </asp:DropDownList>
 </td>   </tr>
    </table>
   
    </div>
    </form>
</body>


Code of Aspx.cs page 


Note:here i used  BindContrydropdown() in Page_Load  because !ispostback check for firsttime and excetue the BindContrydropdown() based on ispostback from next time it skip the page_load 

 if (!IsPostBack)
            {
                BindContrydropdown();
            }


Aspx.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


namespace WebApplication3
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        public string connection = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ToString();

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                BindContrydropdown();
            }
        }


        protected void BindContrydropdown()
        {
            SqlConnection con = new SqlConnection(connection);

            SqlCommand cmd = new SqlCommand("select * from country", con);
          
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            con.Open();
            DataSet ds = new DataSet();

            da.Fill(ds);

            con.Close();

            DropDownList1.DataSource = ds;
            DropDownList1.DataTextField = "countryname";
            DropDownList1.DataValueField = "countryid";
            DropDownList1.DataBind();

        }

      

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int countryid = Convert.ToInt32(DropDownList1.SelectedValue);
            SqlConnection con = new SqlConnection(connection);
            con.Open();

            SqlCommand cmd = new SqlCommand("select * from state where countryid=" + countryid, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            con.Close();
            DropDownList2.DataSource = ds;
            DropDownList2.DataTextField = "StateName";
            DropDownList2.DataValueField = "StateID";
            DropDownList2.DataBind();

        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            int stateid = Convert.ToInt32(DropDownList2.SelectedValue);
                 SqlConnection con = new SqlConnection(connection);
con.Open();
            SqlCommand cmd = new SqlCommand("select * from region where stateid=" + stateid, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
            da.Fill(ds);
con.Close();

            DropDownList3.DataSource = ds;
            DropDownList3.DataTextField = "regionname";
DropDownList3.DataValueField = "regionid";
DropDownList3.DataBind();

        }

     

       







      
       
    }
}