Hi friends..
Im trying to bind a value from dropdownlist placed in gird view to another cell. i want to update a database field with the selected value from dropdownlist and which must be bind to gridview... please help me .. im using sql server2000 as datasource..
public partial class Propertydetails : System.Web.UI.Page
{
protected static string connect;
string ct, struName;
protected void Page_Load(object sender, EventArgs e)
{
string username = Session["UserName"].ToString();
connect = System.Configuration.ConfigurationManager.AppSetti ngs["connect"];
SqlConnection con = new SqlConnection();
con.ConnectionString = connect;
con.Open();
string s = "select PM.RegisterID,PM.PropertyID,PR.PropertyName,CD.Cat egoryName from PropertyMember PM,Property PR,CategoryDetails CD where PM.UserName='" + username + "'and PM.PropertyID=PR.PropertyID and CD.CategoryType=PM.CategoryType";
SqlDataSource1.ConnectionString = connect;
SqlDataSource1.SelectCommand = s;
con.Close();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
// DropDownList ddl1 = new DropDownList();
// //ddl1 = (DropDownList)GridView1.SelectedRow.FindControl("D ropDownList1");
// cname = ddl1.SelectedValue.ToString();
// Session["cname1"] = cname;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string username = Session["UserName"].ToString();
SqlConnection con = new SqlConnection(connect);
string select = "Select CategoryType from CategoryDetails where CategoryName='" + struName + "'";
SqlDataReader dr = null;
SqlCommand cmd1 = new SqlCommand(select, con);
con.Open();
dr = cmd1.ExecuteReader();
while (dr.Read())
{
struName = dr[0].ToString();
}
struName = ((DropDownList)((GridView)sender).Rows[e.RowIndex].FindControl("DropDownList1")).SelectedValue;
e.NewValues["CategoryName"] = struName;
e.Cancel = false;
con.Close();
}
}
please help me..
thanks for all kind of support