Full width home advertisement

Post Page Advertisement [Top]


//display selected state in deopdown
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
             
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            try
            {
                con = new SqlConnection(@"your connection string");
                string str = "Select * from state";

                DropDownList ddl = (e.Row.FindControl("ddlstate") as DropDownList);
                HiddenField hdnval = (HiddenField)e.Row.FindControl("hd");
                cmd = new SqlCommand(str, con);
                dt = new DataTable();
                da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                ddl.DataSource = dt;
                ddl.DataValueField = "sid";
                ddl.DataTextField = "sname";              
                ddl.DataBind();
                ddl.Items.FindByValue(hdnval.Value).Selected = true;
                //GridView1.EditIndex = -1;
              //  show();
            }
            catch { }
        }
    }
//update city
 int id =Convert.ToInt32(((Label) GridView1.Rows[e.RowIndex].FindControl("Label1")).Text);
        string ddlprice = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlstate")).Text;
     
        string c = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3")).Text;
        con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\location\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
        string str = "update city set s_name='"+ddlprice+"', c_name='"+c.ToString()+"' where id='"+id.ToString()+"'";
        con.Open();
        cmd = new SqlCommand(str,con);
        cmd.ExecuteNonQuery();
        con.Close();
        GridView1.EditIndex = -1;
        show();

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib