my complete code is as follows.....
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 System.Data.SqlClient;
using System.Drawing;
public partial class monthlytarget : System.Web.UI.Page
{
dbClass mydb = new dbClass();
SqlConnection sqlcon = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
filldropdown();
fillgrid();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
mydb.myconnection();
SqlCommand cmd = new SqlCommand("insert into monthlytarget(state, projectname, startdate, enddate) values('" + DropDownList1.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "','" + TextBox1.Text + "', '" + TextBox2.Text + "')", mydb.sqlcon);
cmd.ExecuteNonQuery();
GridView1.DataBind();
fillgrid();
}
public void filldropdown()
{
mydb.myconnection();
SqlCommand cmd = new SqlCommand("select * from state", mydb.sqlcon );
SqlDataAdapter adp = new SqlDataAdapter(cmd );
DataSet ds = new DataSet();
adp.Fill(ds );
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "state_name";
DropDownList1.DataValueField = "ID";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem ("--select--", "0"));
SqlCommand cmd1 = new SqlCommand("select * from project_report", mydb.sqlcon);
SqlDataAdapter adp1 = new SqlDataAdapter(cmd1 );
DataSet ds1 = new DataSet();
adp1.Fill(ds1 );
DropDownList2.DataSource = ds1;
DropDownList2.DataTextField = "project_name";
DropDownList2.DataValueField = "ID";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem ("--select--","0"));
}
public void fillgrid()
{
mydb.myconnection();
string query = "SELECT [state],[projectname],[startdate],[enddate] FROM [test].[dbo].[monthlytarget]";
SqlDataAdapter adp = new SqlDataAdapter(query, mydb.sqlcon);
DataSet ds = new DataSet();
adp.Fill(ds, "table0");
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
mydb.myconnection();
SqlCommand cmd = new SqlCommand("select * from project_report where project_name='"+DropDownList2.SelectedValue+"'", mydb .sqlcon );
SqlDataAdapter adp = new SqlDataAdapter(cmd );
DataSet ds = new DataSet();
adp.Fill(ds );
DropDownList3.DataSource = ds;
DropDownList3.DataTextField = "length";
DropDownList3.DataValueField = "ID";
DropDownList3.DataBind();
}
}
Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator