Saturday, 16 March 2013

Template field for gridview

1) right click gridview click addnew column
2)choose field type TemplateField give header text name clik on ok
3)after that right click gridview click on edit template link
4)drag label to itemtemplate field
5)click on label edit databinding link
6)Enter Code expression textbox XPath("productname")  click ok button
XPath use for xml file data.

store xml data to dataset


DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath("~/products.xml"));
//Readxml read xml file and convert into datatable
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();

parameterise grid display


   SqlConnection con = new SqlConnection("Data Source=ANKITA-USER18\\SQL2008R2;Integrated Security=True;Initial Catalog=hrdemo");

        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = new SqlCommand();
        //SqlCommandBuilder c = new SqlCommandBuilder(da);
        da.SelectCommand.CommandText = "select * from emp where id=@p1";
        da.SelectCommand.Connection = con;
        da.SelectCommand.Parameters.Add("@p1", SqlDbType.Int);
        da.SelectCommand.Parameters[0].Value = 1;
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

insert textbox values to the table


  SqlConnection con = new SqlConnection("Data Source=ANKITA-USER18\\SQL2008R2;Integrated Security=True;Initial Catalog=hrdemo");
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into emp values(@p1,@p2)", con);
        cmd.Parameters.Add("@p1", SqlDbType.Int);
        cmd.Parameters.Add("@p2", SqlDbType.VarChar,40);
        cmd.Parameters["@p1"].Value = System.Convert.ToInt32(TextBox1.Text);
        cmd.Parameters[1].Value = TextBox2.Text;
        int ans = cmd.ExecuteNonQuery();
        Response.Write(ans.ToString() + "records inserted");

gridview bind


 SqlConnection con = new SqlConnection("Data Source=ANKITA-USER18\\SQL2008R2;Integrated Security=True;Initial Catalog=hrdemo") ;
    SqlDataAdapter da = new SqlDataAdapter("select * from emp", con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
   

dropdownlist bind


 SqlConnection con = new SqlConnection("Data Source=ANKITA-USER18\\SQL2008R2;Integrated Security=True;Initial Catalog=hrdemo");
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from emp", con);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            String str = dr[0].ToString() + "  :" + dr[1].ToString();
            DropDownList1.Items.Add(str);
        }

Friday, 15 February 2013

Izenda how to visible setting button for non admin user


public override void ConfigureSettings()
        {
            
            AdHocSettings.ShowSettingsButtonForNonAdmins = true;

        }