sreenu kolusu

sreenu kolusu

  • NA
  • 38
  • 178.1k

18examples

Aug 9 2012 2:52 PM

ADS LINK:

http://dotnet-ramaprasad.blogspot.com/

http://www.ianatkinson.net/computing/adcsharp.htm

links:

exports gridview to pdf

http://r4r.co.in/asp.net/01/tutorial/asp.net/Export%20gridview%20to%20pdf%20in%20asp.net%20using%20c-Sharp.shtml.

Microsoft partner

https://partners.microsoft.com/partnerprogram/IndividualProfile.aspx?a=1

3632844

Physical location of sharepoint dll

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\ISAPI

1.Display all the WebApplicatoion and sites in Central Administration

 

  SPSite site = new SPSite(@"http://sys-pc:1212/sites/practise");

 

        SPWeb web = site.OpenWeb();

 

        web.AllowUnsafeUpdates = true;

        foreach (SPWebApplication spw in SPWebService.ContentService.WebApplications)

        {

           //Response.Write(spw.DisplayName.ToString());

            foreach (SPSite sps in spw.Sites)

            {

                //Response.Write(sps.Url.ToString());

                foreach (SPWeb spw1 in sps.AllWebs)

                {

                    Response.Write(spw1.Name.ToString() + "<br>" + spw1.Url.ToString());

                }

            }

        }

 

2.createing the customlist

SPSite sps = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb spw = sps.OpenWeb();

        spw.AllowUnsafeUpdates = true;

        Guid newlist = spw.Lists.Add("obulreddy", "obulreddy Information", SPListTemplateType.GenericList);

        SPList spl = spw.Lists[newlist];

        SPFieldNumber fldEmployeeId = (SPFieldNumber)spl.Fields.CreateNewField(SPFieldType.Number.ToString(), "EmployeeId");

        fldEmployeeId.Description = "Emloyee UniqueID";

        fldEmployeeId.Required = true;

        fldEmployeeId.DisplayFormat = SPNumberFormatTypes.NoDecimal;

        SPFieldText fldEmployeeName = (SPFieldText)spl.Fields.CreateNewField(SPFieldType.Text.ToString(), "EmployeeName");

        fldEmployeeName.Required = true;

        fldEmployeeName.Description = "EmployeeName";

        SPFieldNumber fldSalary = (SPFieldNumber)spl.Fields.CreateNewField(SPFieldType.Number.ToString(), "Salary");

        fldSalary.Description = "Employee Salary";

        fldSalary.Required = true;

        fldSalary.DisplayFormat = SPNumberFormatTypes.NoDecimal;

        SPFieldNumber fldDeptNo = (SPFieldNumber)spl.Fields.CreateNewField(SPFieldType.Number.ToString(), "DeptNo");

        fldDeptNo.Description = "Department Number";

        fldDeptNo.Required = true;

        fldDeptNo.DisplayFormat = SPNumberFormatTypes.NoDecimal;

        SPFieldDateTime fldDateofBirth = (SPFieldDateTime)spl.Fields.CreateNewField(SPFieldType.DateTime.ToString(), "DateofBirth");

        fldDateofBirth.Description = "Emloyee Birth Date";

        fldDateofBirth.Required = true;

        fldDateofBirth.DisplayFormat = SPDateTimeFieldFormatType.DateTime;

        spl.Fields.Add(fldEmployeeId);

        spl.Fields.Add(fldEmployeeName);

        spl.Fields.Add(fldSalary);

        spl.Fields.Add(fldDeptNo);

        spl.Fields.Add(fldDateofBirth);

        spl.Update();

        SPView Defaultview = spl.DefaultView;

        Defaultview.ViewFields.Add(spl.Fields["EmployeeId"]);

        Defaultview.ViewFields.Add(spl.Fields["EmployeeName"]);

        Defaultview.ViewFields.Add(spl.Fields["Salary"]);

        Defaultview.ViewFields.Add(spl.Fields["DeptNo"]);

        Defaultview.ViewFields.Add(spl.Fields["DateofBirth"]);

        Defaultview.Update();

 

Add the customlist using usercontrol

 

 

  SPSite site = new SPSite("http://sys-pc:1919/Fms");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList tasklist = web.Lists["AddSalary"];

        SPListItem newtask = tasklist.Items.Add();

        newtask["EmpName"] = ddl_empname.SelectedItem;

        newtask["salary"] = txt_empsalary.Text;

        newtask["month"] = ddl_month.SelectedItem;

        newtask["NoofDays"] = txt_noofdays.Text;

        newtask["Tax"] = txt_tax.Text;

        newtask["TA"] = txt_ta.Text;

        newtask["DA"] = txt_da.Text;

        newtask["HRA"] = txt_hra.Text;

        newtask["Net"] = txt_Net.Text;

        newtask.Update();

        lbldisplay.Text = "successfully added";

3. Display empid in customlist

  

 

        SPSite sps = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb spw = sps.OpenWeb();

        SPList spl = spw.Lists["Employee2"];

        foreach (SPListItem item in spl.Items)

        {

            string s = item["EmployeeId"].ToString();

            Response.Write(s);

        }

4. create document library

 

  SPSite spsite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb spweb = spsite.OpenWeb();

        spweb.AllowUnsafeUpdates = true;

        Guid newguid = spweb.Lists.Add("obulDoc4", "obulDoc4description", SPListTemplateType.DocumentLibrary);

        SPList splist = spweb.Lists[newguid];

        splist.OnQuickLaunch = true;

        splist.EnableVersioning = true;

        splist.Update();

 

5.Display the all the document libraries in the dropdown

 

 

        SPSite spsite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb spweb = spsite.OpenWeb();

        SPListCollection splc = spweb.GetListsOfType(SPBaseType.DocumentLibrary);

        foreach (SPList spl in splc)

        {

            dddisplayselectedlibrary.Items.Add(spl.Title.ToString());

            Response.Write(spl.Title.ToString());

 

 

        }     

6.Displaying the users from different groups

 

SPSite spsite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb spweb = spsite.OpenWeb();

        foreach (SPGroup spg1 in spweb.Groups)

        {

            Response.Write(spg1.Name);

            foreach (SPUser spu in spg1.Users)

            {

                Response.Write(spu.Name);

            }

        }

7.Delete the user from specific group

 

SPSite sps = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb spw = sps.OpenWeb();

        SPGroup spg = spw.Groups["viewer1"];

        try

        {

 

            SPUser spu = spw.AllUsers[@"SYS-PC\administrator"];

            spg.RemoveUser(spu);

            spg.Update();

            Response.Write("Deleted SuccessFully");

        }

        catch

        {

            Response.Write("User is not there ");

        }

    }

8.move the users from one group to another group

 

SPSite sps = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb spw = sps.OpenWeb();

        spw.AllowUnsafeUpdates = true;

        SPGroup spg = spw.Groups["viewers"];

        foreach (SPUser spu in spg.Users)

        {

            spw.Groups["Approvers"].AddUser(spu);

        }

 

9. creating dept in customlist

 

   SPSite site = new SPSite(@"http://sys-pc:1212/sites/practise");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        Guid newlist = web.Lists.Add("dept1", "department information1", SPListTemplateType.GenericList);

        SPList list1 = web.Lists[newlist];

        SPFieldNumber deptno = (SPFieldNumber)list1.Fields.CreateNewField(SPFieldType.Number.ToString(), "deptno");

        deptno.Description = "Department Number";

        deptno.Required = true;

        deptno.DisplayFormat = SPNumberFormatTypes.NoDecimal;

        SPFieldText deptname = (SPFieldText)list1.Fields.CreateNewField(SPFieldType.Text.ToString(), "deptname");

        deptname.Description = "Department name";

        deptname.Required = true;

        SPFieldText deptcity = (SPFieldText)list1.Fields.CreateNewField(SPFieldType.Text.ToString(), "deptcity");

        deptcity.Description = "Department city";

        deptcity.Required = true;

        list1.Fields.Add(deptno);

        list1.Fields.Add(deptname);

        list1.Fields.Add(deptcity);

        list1.Update();

        SPView defview = list1.DefaultView;

        defview.ViewFields.Add(list1.Fields["deptno"]);

        defview.ViewFields.Add(list1.Fields["deptname"]);

        defview.ViewFields.Add(list1.Fields["deptcity"]);

        defview.Update();

        lblmessage.Text = "department list created";

 

10.Add the users in customlist

 

  SPSite rootSite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb web = rootSite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList tasklist = web.Lists[txtlist.Text.ToString()];

        SPListItem newtask = tasklist.Items.Add();

        newtask["Title"] = txttitle.Text;

        newtask["student number"] = txtsno.Text;

        newtask["studlastname"] = txtstudlastname.Text;

        newtask["StudentFirstName"] = txtstudlastname.Text;

        newtask["StudentCity"] = txtstudcity.Text;

        newtask[""] = txtstudaddress.Text;

        newtask.Update StudentAddress ();

        lblmessage.Text = "one list inserted";

 

 

 

11.Add the user to group  from enter into the textbox

 

   SPSite site = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPUser user =web.Users[txtaddtheuser.Text];

        web.Groups["niv4group"].AddUser(user);

        Response.Write("add the user");

12.delete the user  from specific group  when enter into the textbox

 

      SPSite site=new SPSite("http://sys-pc:1212/sites/practise");

       SPWeb web = site.OpenWeb();

       web.AllowUnsafeUpdates = true;

       SPGroup grp = web.Groups["niv4group"];

       SPUser user = web.AllUsers[TextBox1.Text];

       grp.RemoveUser(user);

       grp.Update();

       Response.Write("delete  the user");

 

 

 

12.Delete the users in customlist

 

   SPSite rootSite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb web = rootSite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPListItemCollection listItems = web.Lists[txtlist.Text].Items;

        int itemCount = listItems.Count;

        for (int k = 0; k < itemCount; k++)

        {

            SPListItem item = listItems[k];

            if (txtsno.Text == item["student number"].ToString())

            {

                listItems.Delete(k);

            }

        }

        lblmessage.Text = "One item deleted";

13.  gridview custom row updateing

protected void gv_custom_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

        SPSite mysite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb web = mysite.OpenWeb();

        web.AllowUnsafeUpdates=true;

        try

        {

            SPList mylist = web.Lists["Employee"];

            SPListItem mylistitem =mylist.Items.GetItemById(Convert.ToInt32(@gv_custom.Rows[e.RowIndex].Cells[6].Text));

           

            TextBox txt_id = (TextBox)gv_custom.Rows[e.RowIndex].Cells[2].Controls[0];

            TextBox txt_name = (TextBox)gv_custom.Rows[e.RowIndex].Cells[3].Controls[0];

            TextBox txt_salary = (TextBox)gv_custom.Rows[e.RowIndex].Cells[4].Controls[0];

            TextBox txt_dob = (TextBox)gv_custom.Rows[e.RowIndex].Cells[5].Controls[0];

 

            // = Convert.ToInt32(txt_id.Text);

            mylistitem["EmployeeID"] =Convert.ToInt32( txt_id.Text);

           mylistitem ["EmployeeName"] =txt_name.Text;

            mylistitem ["EmployeeSalary"] = Convert.ToInt32(txt_salary.Text);

            mylistitem["DateOfBirth"] = Convert.ToDateTime( txt_dob.Text);

            mylistitem.Update();

            Response.Write("Successfully Updated");

 

 

        }

 

        catch (Exception ex)

        {

            Response.Write("Not Updating" + ex.Message);

        }

 

    }

 

    protected void gv_custom_RowEditing(object sender, GridViewEditEventArgs e)

    {

        gv_custom.EditIndex = e.NewEditIndex;

        bindgrid();

 

    }

    protected void gv_custom_RowDeleting(object sender, GridViewDeleteEventArgs e)

    {

 

        SPSite mysite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb web = mysite.OpenWeb();

        web.AllowUnsafeUpdates=true;

       // string str =

        try

        {

            SPList mylist = web.Lists["Employee"];

            mylist.Items.DeleteItemById(Convert.ToInt32(@gv_custom.Rows[e.RowIndex].Cells[6].Text));

            mylist.Update();

            Response.Write("Successfully Deleted");

            bindgrid();

 

        }

        catch (Exception ex)

        {

            Response.Write("Not Deleted &nbsp;&nbsp;" + ex.Message);

        }

 

    }

    protected void gv_custom_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

    {

        gv_custom.EditIndex = -1;

        bindgrid();

 

    }

    public void bindgrid()

    {

        SPSite mysite = new SPSite("http://sys-pc:1212/sites/practise");

        SPWeb myweb = mysite.OpenWeb();

        myweb.AllowUnsafeUpdates = true;

        try

        {

            SPList mylist = myweb.Lists["Employee"];

            DataTable mydt = mylist.GetItems(mylist.DefaultView).GetDataTable();

            gv_custom.DataSource = mydt;

            gv_custom.DataBind();

        }

        catch (Exception ex)

        {

            Response.Write(ex.Message);

        }

    }

    protected void btn_custom_Click(object sender, EventArgs e)

    {

        bindgrid();

    }

    protected void gv_custom_SelectedIndexChanged(object sender, EventArgs e)

    {

 

    }

 

 

 

14.get the  document lilbrary  and its view and get the lists and its view  (treeview format).     

 

  protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)

    {

        if (TreeView1.SelectedNode.Text == "Documents")

        {

            FillDocLib();

        }

        if (TreeView1.SelectedNode.Text == "Lists")

        {

            FillLists();

        }

    }

    void FillDocLib()

    {

 

        SPSite site = new SPSite(@"http://sys-pc:1212/sites/practise/");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        //Get the Document Library and its view

        SPListCollection splc = web.GetListsOfType(SPBaseType.DocumentLibrary);

        foreach (SPList spl in splc)

        {

            TreeNode node = new TreeNode(spl.Title);

            node.SelectAction = TreeNodeSelectAction.Expand;

            TreeView1.SelectedNode.ChildNodes.Add(node);

            SPList list = web.Lists[spl.Title];

            SPListItemCollection items = list.Items;

            foreach (SPListItem item in items)

            {

                TreeNode newNode = new TreeNode(item.Name);

                newNode.SelectAction = TreeNodeSelectAction.Expand;

                node.ChildNodes.Add(newNode);

 

            }

        }

 

    }

    void foldersandfiles()

    {

        SPSite site = new SPSite(@"http://sys-pc:1212/sites/practise/");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPFolderCollection sfc1 = web.Folders;

        foreach (SPFolder sf1 in sfc1)

        {

            TreeNode node = new TreeNode(sf1.Name);

            node.SelectAction = TreeNodeSelectAction.Expand;

            TreeView1.SelectedNode.ChildNodes.Add(node);

            SPFolder sf2 = web.Folders[sf1.Name];

            SPFileCollection spfc1 = sf2.Files;

            foreach (SPFile f2 in spfc1)

            {

                TreeNode newnode = new TreeNode(f2.Name);

                newnode.SelectAction = TreeNodeSelectAction.Expand;

                node.ChildNodes.Add(newnode);

            }

        }

    }

    void FillLists()

    {

        SPSite site = new SPSite(@"http://sys-pc:1212/sites/practise/");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        //Get the Document Library and its view

        SPListCollection splc = web.GetListsOfType(SPBaseType.GenericList);

        foreach (SPList spl in splc)

        {

            TreeNode node = new TreeNode(spl.Title);

            node.SelectAction = TreeNodeSelectAction.Expand;

            TreeView1.SelectedNode.ChildNodes.Add(node);

            SPList list = web.Lists[spl.Title];

            SPListItemCollection items = list.Items;

            foreach (SPListItem item in items)

            {

                TreeNode newNode = new TreeNode(item.Name);

                newNode.SelectAction = TreeNodeSelectAction.Expand;

                node.ChildNodes.Add(newNode);

 

            }

        }

    }

    

15.How to run .exe in aspx

 

protected void Page_Load(object sender, EventArgs e) 

  {

System.Diagnostics.Process p = new System.Diagnostics.Process();

        p.StartInfo.FileName = "C://MenuPages_MYSQL_Version2.8.88.exe";

        p.Start();

 

}

 

 

 

16. user edit or not

 

SPWeb myWeb = SPContext.Current.Web;

        myWeb.AllowUnsafeUpdates = true;

        SPUser user = myWeb.CurrentUser;

        string username = user.Name.Substring(user.Name.IndexOf("\\") + 1);

        string groupname = null;

        foreach (SPGroup grp in user.Groups)

        {

            groupname = grp.Name;

        }

Mail fireing:

<a href="mailto:[email protected]&Subject=Feedback on Fine Point">feedback</a>(or)

<a href="mailto:[email protected]?subject=Feedback%20on%20obul%20">feedback</a>(or)

<a href="mailto:[email protected]&subject=obulrequest">obul

feedback</a>

 

 

18.Gridview all rows save at a time

 

  protected void btnsave_Click(object sender, EventArgs e)

    {

        SqlConnection con = new SqlConnection("User Id=sharepoint;password=sharePoint;database=kkn;server=192.168.0.111");

        SqlCommand cmd = new SqlCommand();

        cmd.Connection = con;

        con.Open();

        if (GridView1.Rows.Count > 0)

        {

            foreach (GridViewRow row in GridView1.Rows)

            {

                TextBox box1 = (TextBox)row.Cells[1].FindControl("TextBox1");

 

                TextBox box2 = (TextBox)row.Cells[1].FindControl("TextBox5");

 

                TextBox box3 = (TextBox)row.Cells[2].FindControl("TextBox2");

                TextBox box4 = (TextBox)row.Cells[3].FindControl("TextBox3");

 

                DropDownList ddlcity = (DropDownList)row.Cells[0].FindControl("ddlcities");

                cmd.CommandText = "insert into team values('" + ddlcity.SelectedItem.ToString() + "','" + box1.Text + "','" + box2.Text + "','" + box3.Text + "','" + box4.Text + "')";

                cmd.ExecuteNonQuery();

 

 

 

            }

            con.Close();

        }

    }

 

 

Gridview all rows delete at a time:

 

   protected void Btnbankdelete_Click(object sender, EventArgs e)

    {

        foreach (GridViewRow row in Grid_bankdetails.Rows)

        {

            CheckBox chk = (CheckBox)row.FindControl("Chkbanksingledelete");

            if (chk.Checked)

            {

                Label lbl = (Label)row.FindControl("Label7");

                SPSite mysite = new SPSite("http://sys-pc:1919");

                SPWeb web = mysite.OpenWeb();

                web.AllowUnsafeUpdates = true;

                SPList list = web.Lists["Bank Details"];

                SPListItem item = list.GetItemById(int.Parse(lbl.Text));

                item.Delete();

            }

        }

        BindBankdetails();

 

    }

 

Gridview row updateing

 

  protected void Grid_familydetails_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

        SPSite mysite = new SPSite("http://sys-pc:1919");

        SPWeb web = mysite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Family Details"];

        TextBox txtid = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox6");

        SPListItem itemid = list.GetItemById(int.Parse(txtid.Text));

        TextBox ename = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox1");

        TextBox empid = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox2");

        TextBox deptname = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox3");

        TextBox relation = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox4");

        TextBox age = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox5");

        itemid["Emp Name"] = ename.Text;

        itemid["EmpId"] = empid.Text;

        itemid["DepartmentName"] = deptname.Text;

        itemid["Relation"] = relation.Text;

        itemid["Age"] = age.Text;

        itemid.Update();

        Grid_familydetails.EditIndex = -1;

        Bindfamilydetails();

    }

 

Gridview row command click on nextpage:

   <ItemTemplate>  <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"  CommandName="Edit" Text="Edit" CommandArgument='<%# Bind("ID") %>'></asp:LinkButton>

    </ItemTemplate>

   protected void Grid_bankdetails_RowCommand(object sender, GridViewCommandEventArgs e)

    {

        if (e.CommandName.Equals("Edit"))

        {

            Response.Redirect("EditBankdetails.aspx?empid=" + e.CommandArgument);

        }

    }

Nextpage:

 

  string empid =null;

    protected void Page_Load(object sender, EventArgs e)

    {

        empid = Request.QueryString["eid"].ToString();

        if(!IsPostBack)

        filldetails();

    }

 

    void filldetails()

    {

        SqlConnection con = new SqlConnection("User Id =sharepoint;password=sharePoint;database=EMS;server=192.168.0.111");

        SqlCommand cmd = new SqlCommand();

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Connection = con;

        cmd.CommandText = "ViewEmp";

        SqlDataAdapter da = new SqlDataAdapter();

        da.SelectCommand = cmd;

        DataSet ds = new DataSet();

        da.Fill(ds, "emp1");

        foreach (DataRow dr in ds.Tables["emp1"].Rows)

        {

            if (dr["emp_id"].ToString().Equals(empid))

            {

                txt_eid.Text = dr["emp_id"].ToString();

                txt_ename.Text = dr["emp_fname"].ToString();

                txt_elname.Text = dr["emp_lname"].ToString();

                txt_emname.Text = dr["emp_mname"].ToString();

                txt_ejdate.Text = dr["emp_join_date"].ToString();

                txt_edateofbirth.Text = dr["emp_dob"].ToString();

                txt_eemail.Text = dr["emp_email"].ToString();

                txt_econtactno.Text = dr["emp_contactno"].ToString();

                txt_eextention.Text = dr["emp_ext"].ToString();

                txt_ecproject.Text = dr["emp_current_project"].ToString();

                txt_eaddress.Text = dr["emp_address"].ToString();

                txt_ecity.Text = dr["emp_city"].ToString();

                txt_ecitypin.Text = dr["emp_city_pincode"].ToString();

                txt_egender.Text = dr["emp_gender"].ToString();

                ddl_emaritalstatus.Text = dr["emp_marital_status"].ToString();

                hid_emp_personalid.Value = dr["emp_personal_id"].ToString();

                break;

            }

        }

 

Insert:

 

protected void btn_insert_Click(object sender, EventArgs e)

    {

        SqlConnection con = new SqlConnection("User Id =sharepoint;password=sharePoint;database=EMS;server=192.168.0.111");

        SqlCommand cmd = new SqlCommand();

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Connection = con;

        cmd.CommandText = "AddEmp";

        con.Open();

        cmd.Parameters.AddWithValue("@emp_id", Convert.ToInt32(txt_eid.Text));

        cmd.Parameters.AddWithValue("@emp_fname", txt_ename.Text);

        cmd.Parameters.AddWithValue("@emp_lname", txt_elname.Text);

        cmd.Parameters.AddWithValue("@emp_mname", txt_emname.Text);

        cmd.Parameters.AddWithValue("@emp_join_date", DateTime.Parse(txt_ejdate.Text));

        cmd.Parameters.AddWithValue("@emp_dob", DateTime.Parse(txt_edateofbirth.Text));

        cmd.Parameters.AddWithValue("@emp_email", txt_eemail.Text);

        cmd.Parameters.AddWithValue("@emp_contactno", int.Parse(txt_econtactno.Text));

        cmd.Parameters.AddWithValue("@emp_ext", int.Parse(txt_eextention.Text));

        cmd.Parameters.AddWithValue("@emp_current_project", txt_ecproject.Text);

        cmd.Parameters.AddWithValue("@emp_address", txt_eaddress.Text);

        cmd.Parameters.AddWithValue("@emp_city", txt_ecity.Text);

        cmd.Parameters.AddWithValue("@emp_city_pincode", int.Parse(txt_ecitypin.Text));

        cmd.Parameters.AddWithValue("@emp_gender", txt_egender.Text);

        cmd.Parameters.AddWithValue("@emp_marital_status", ddl_emaritalstatus.Text);

        cmd.Parameters.AddWithValue("@emp_personal_id", int.Parse(hid_emp_personalid.Value));

        cmd.ExecuteNonQuery();

        con.Close();

 

        Response.Redirect("~/EMS/Pages/ViewEmployees.aspx");

    }

 

 

 

Gridview row updateing

 

    protected void Grid_familydetails_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

        SPSite mysite = new SPSite("http://sys-pc:1919");

        SPWeb web = mysite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Family Details"];

        TextBox txtid = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox6");

        SPListItem itemid = list.GetItemById(int.Parse(txtid.Text));

        TextBox ename = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox1");

        TextBox empid = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox2");

        TextBox deptname = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox3");

        TextBox relation = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox4");

        TextBox age = (TextBox)Grid_familydetails.Rows[e.RowIndex].FindControl("TextBox5");

        itemid["Emp Name"] = ename.Text;

        itemid["EmpId"] = empid.Text;

        itemid["DepartmentName"] = deptname.Text;

        itemid["Relation"] = relation.Text;

        itemid["Age"] = age.Text;

        itemid.Update();

        Grid_familydetails.EditIndex = -1;

        Bindfamilydetails();

    }

Gridviewview Editing

 

  protected void Grid_familydetails_RowEditing(object sender, GridViewEditEventArgs e)

    {

        Grid_familydetails.EditIndex = e.NewEditIndex;

        Bindfamilydetails();

    }

GRIDBIEW All checkbox select at a time:

   protected void Chkpersonsingledelete_CheckedChanged(object sender, EventArgs e)

    {

        CheckBox chk = (CheckBox)Grid_personaldetails.HeaderRow.FindControl("Chkpersonalalldelete");

        chk.Checked = false;

    }

    protected void ChkTechnicalalldelete_CheckedChanged(object sender, EventArgs e)

    {

        foreach (GridViewRow row in Grid_technicaldetails.Rows)

        {

            CheckBox chk = (CheckBox)row.FindControl("ChkTechnicaldelete");

            chk.Checked = true;

        }

    }

 

GET THE VALUES IN GRIDVIEW

    private void getdata()   

{   

    try   

    {

SPSite site = new SPSite(@"http://sys-pc/sites/Mysite/Mysite");         

  SPWeb web = site.OpenWeb();         

  SPList list = web.Lists["Dept1"];    

       DataTable table = list.GetItems(list.DefaultView).GetDataTable();    

       GV_List.DataSource = table;    

       GV_List.DataBind();   

    }        catch (Exception ex) 

      {      

     Response.Write(ex.Message); 

      } 

  }

 

Bind the values in dropdownlist  from custom list

   SPSite mysite = new SPSite("http://sys-pc:1919/Pages");

        SPWeb myweb = mysite.OpenWeb();

        myweb.AllowUnsafeUpdates = true;

        SPList list = myweb.Lists["Conference Halls"];

        foreach (SPListItem item in list.Items)

        {

            string names = item["HallName"].ToString();

            int id = Convert.ToInt32(item["HallId"]);

            DDL_conferenceroms.Items.Add(names);

            DDL_conferenceroms.SelectedIndex = 0;

                     

        }

How to get the data in datatable from customlist and bind in Gridview

   SPSite site = new SPSite(@"http://sys-pc:1919/Pages");

            SPWeb web = site.OpenWeb();

            web.AllowUnsafeUpdates = true;

            SPList list = web.Lists["Conference Book"];

            DataTable  datatable=list.GetItems(list.DefaultView).GetDataTable();

            Gridview1.datasource=datatable;

            Gridview1.databind();

 

Another Example:

How to Bind the Data in Gridview from Customlist

  SPSite rootSite = new SPSite("http://sys-pc:1919");

        SPWeb web = rootSite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Passport Details"];

        DataTable dt = list.GetItems(list.DefaultView).GetDataTable();

        GridView1.DataSource = dt;

        GridView1.DataBind();

 

 

How to delete row in gridview using customlist:

protected void Btndelete_Click(object sender, EventArgs e)

    {

   

        foreach (GridViewRow row in Grid_personaldetails.Rows)

        {

            CheckBox chk = (CheckBox)row.FindControl("Chkpersonsingledelete");

            if (chk.Checked)

            {

                Label lbl = (Label)row.FindControl("Label7");

                int id = Convert.ToInt32(lbl.Text);

                SPSite mysite = new SPSite("http://sys-pc:1919");

                SPWeb web = mysite.OpenWeb();

                web.AllowUnsafeUpdates = true;

                SPList list = web.Lists["Personal Details"];

                SPListItem item = list.Items.GetItemById(id);

                string id1 = item["ID"].ToString();

                item.Delete();

                Bindpersonaldetails();

            }

 

        }

    }

Updateing gridview using custom list(simple)

 

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

        SPSite mysite = new SPSite("http://sys-pc:1919");

        SPWeb web = mysite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Passport Details"];

        TextBox txtid = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4");    

        SPListItem itemid = list.GetItemById(int.Parse(txtid.Text));

        TextBox txt_passportno = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");

        TextBox txt_expirtdate = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3");      

        itemid["ExpiryDate"] = txt_expirtdate.Text;

        itemid["PassportNumber"] = txt_passportno.Text;

        itemid.Update();

        GridView1.EditIndex = -1;

        bindgridview();       

    }

 

Calendar control previous dates

   if (Convert.ToDateTime(Calendar1.SelectedDate.ToShortDateString()).CompareTo(DateTime.Now.Date) < 0)

    {

error mesange;

}

else

{

write the code

}

Updateing row in gridview using customlist

  protected void Grid_personaldetails_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

        SPSite mysite = new SPSite("http://sys-pc:1919");

        SPWeb web = mysite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Personal Details"];

        TextBox txtid = (TextBox)Grid_personaldetails.Rows[e.RowIndex].FindControl("TextBox7");

        int id1 = Convert.ToInt32(txtid.Text);

        SPListItem item = list.Items.GetItemById(id1);

        string id = item["ID"].ToString();

        SPListItem itemid = list.GetItemById(int.Parse(id));

        TextBox txtfirstname = (TextBox)Grid_personaldetails.Rows[e.RowIndex].FindControl("TextBox1");

        TextBox txtempjoindate = (TextBox)Grid_personaldetails.Rows[e.RowIndex].FindControl("TextBox2");

        TextBox txtempemail = (TextBox)Grid_personaldetails.Rows[e.RowIndex].FindControl("TextBox3");

        TextBox txtempcontactno = (TextBox)Grid_personaldetails.Rows[e.RowIndex].FindControl("TextBox4");

        TextBox txtempaddress = (TextBox)Grid_personaldetails.Rows[e.RowIndex].FindControl("TextBox5");

        TextBox txtempcity = (TextBox)Grid_personaldetails.Rows[e.RowIndex].FindControl("TextBox6");

        itemid["FirstName"] = txtfirstname.Text;

        itemid["EmpJoindate"] = txtempjoindate.Text;

        itemid["EmpEmail"] = txtempemail.Text;

        itemid["EmployeeContactNo"] = txtempcontactno.Text;

        itemid["EmployeeAddress"] = txtempaddress.Text;

        itemid["EmployeeCity"] = txtempcity.Text;

        itemid.Update();

        Grid_personaldetails.EditIndex = -1;

        Bindpersonaldetails();

    }

 

How to get the customlist id

 

SPSite site = new SPSite(@"http://sys-pc:1919/Pages");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Conference Book"];

        DataTable datatable = list.GetItems(list.DefaultView).GetDataTable();

        string id="0";

        foreach (DataRow dr in datatable.Rows)

        {

if (dr["LinkTitle"].ToString() == name && (DateTime.Parse(dr["Booked_x0020_Date"].ToString()) == selectdate) && (int.Parse(dr["Start_x0020_Time"].ToString()) == starttime))

            {

 

                id = dr["ID"].ToString();

            }

           SPListItem item = list.GetItemById(int.Parse(id));        

            txt_selectstarttime.Text = Convert.ToInt32(item["StartToString();

            txt_endtime.Text = Convert.ToInt32(item["End Time"]).ToString();

 

update :

 

same above  and add item .update()

gridview  :

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">

    <Columns>

        <asp:TemplateField>

            <AlternatingItemTemplate>

                <asp:CheckBox ID="CheckBox1" runat="server" />

            </AlternatingItemTemplate>

            <ItemTemplate>

                <asp:CheckBox ID="CheckBox1" runat="server" />

            </ItemTemplate>

            <HeaderTemplate>

                <asp:CheckBox ID="cbSelectAll" runat="server" Text="Select All" OnClick="selectAll(this)" />

            </HeaderTemplate>

            <HeaderStyle HorizontalAlign="Left" />

            <ItemStyle HorizontalAlign="Left" />

        </asp:TemplateField>

    </Columns>

</asp:GridView>

<script type="text/javascript">

    function SelectAll(id) {

        var frm = document.forms[0];

        for (i=0;i<frm.elements.length;i++) {

            if (frm.elements[i].type == "checkbox") {

                frm.elements[i].checked = document.getElementById(id).checked;

            }

        }

    } 

</script>

 

 

 

How to Add user to ADS:

 

   protected void Button1_Click(object sender, EventArgs e)

    {

  

        DirectoryEntry myLdapConnection = createDirectoryEntry();

        // define vars for user

        String domain = "192.168.0.86";

        String first = txt_firstname.Text;

        String last = txt_Lastname.Text;

        String description = txt_description.Text;

        string password = txt_password.Text;

        String[] groups = {"sp developer"};

        String username = first.ToLower() + last.Substring(0, 1).ToLower();

        String homeDrive = "D:";

        String homeDir = @"users\" + username;

 

        try

        {

            if (createUser(myLdapConnection, domain, first, last, escription,

                 password, groups, username, homeDrive, homeDir, true) == 0)

            {

 

                Console.WriteLine("Account created!");

                Console.ReadLine();

            }

 

            else

            {

                Console.WriteLine("Problem creating account");

                Console.ReadLine();

            }

        }

 

        catch (Exception ex)

        {

            lblmessage.Text = ex.Message;

        }

        finally

        {

            lblmessage.Text = "Successfully Added";

        }

    }

static int createUser(DirectoryEntry myLdapConnection, String domain, String first, String last, String description, string password,                      String[] groups, String username, String homeDrive,String homeDir, bool enabled)

    {

        // create new user object and write into AD 

        first = first.Trim();

       DirectoryEntry user = myLdapConnection.Children.Add("CN="+first,"user");

        // User name (domain based)  

        user.Properties["userprincipalname"].Add(username + "@" + domain);

 

        // User name (older systems) 

        user.Properties["samaccountname"].Add(username);

 

        // Surname 

        user.Properties["sn"].Add(last);

 

        // Forename 

        user.Properties["givenname"].Add(first);

 

        // Display name 

        user.Properties["displayname"].Add(first + " " + last);

        // Description 

        user.Properties["description"].Add(description);

        // E-mail 

        user.Properties["mail"].Add(first + "." + last + "@" + domain);

        // Home dir (drive letter) 

        user.Properties["homedirectory"].Add(homeDir);

        // Home dir (path) 

        user.Properties["homedrive"].Add(homeDrive);

        user.CommitChanges();

        // set user's password 

        DirectoryEntry user1 = new DirectoryEntry("LDAP://192.168.0.86/CN=" + first + ",CN=Users,DC=nivistalocal,DC=Com");

        int val = (int)user1.Properties["userAccountControl"].Value;

        user1.Properties["userAccountControl"].Value = val & ~0x2;

        //ADS_UF_NORMAL_ACCOUNT;

        user1.CommitChanges();       

        SetPassword(user, password);       

        return 0;

       

    }

   

    private static void SetPassword(DirectoryEntry UE, string password)

    {

        object[] oPassword = new object[] { password };

        object ret = UE.Invoke("SetPassword", oPassword);

        UE.CommitChanges();

     

    }

    static DirectoryEntry createDirectoryEntry()

    {

        // create and return new LDAP connection with desired settings 

 

        DirectoryEntry ldapConnection = new DirectoryEntry("LDAP://192.168.0.86/CN=users,DC=nivistalocal,DC=com","Administrator","@Nivista");

       // ldapConnection.Path               = "LDAP://nivistalocal.com/CN=users,DC=nivistalocal,DC=com";

     

        ldapConnection.AuthenticationType = AuthenticationTypes.Secure;

        return ldapConnection;

    }

HOW TO GET THE USERS FROM ADS:

 

   {

        getusernames();

    }

    protected void getusernames()

    {  

        dt.Columns.Add("All users", typeof(string));

        dt.Columns.Add("email",typeof(String));

        dt.Columns.Add("description", typeof(String));

      

        DirectoryEntry allnames = new DirectoryEntry("LDAP://192.168.0.86/CN=Users,DC=nivistalocal,DC=Com", "Administrator", "@Nivista", AuthenticationTypes.Secure);

       

 

        foreach (DirectoryEntry child in allnames.Children)

        {

           

            string useremail = null;

            string userdescription = null;

            //if (child.Properties["cn"].Count > 0 && child.Properties["mail"].Count > 0 && child.Properties["description"].Count>0)

            //{

            //    s = (String.Format("{0,-20} : {1}:{2}", child.Properties["cn"][0].ToString(), child.Properties["mail"][0].ToString(), child.Properties["description"][0].ToString()));

            //    s1 = child.Properties["description"][0].ToString();

 

            //}

            DataRow dr = dt.NewRow();

            string username = child.Properties["cn"][0].ToString();

            if (child.Properties["cn"].Count > 0 && child.Properties["mail"].Count > 0 && child.Properties["description"].Count > 0)

            {

                useremail = child.Properties["mail"][0].ToString();

                if (useremail != null)

                {

                    dr["email"] = useremail;

                }

                userdescription = child.Properties["description"][0].ToString();

                if (userdescription != null)

                {

                    dr["description"] = userdescription;

                }

            }

          

            dr["All users"] = username;        

         

            dt.Rows.Add(dr);          

         

        }

           

        GridView1.DataSource = dt;

        GridView1.DataBind();

     

    }

Specific row  get the  datatable:

 

   protected GridView Bindpassportdetails()

    {

        SPSite rootSite = new SPSite("http://sys-pc:1919");

        SPWeb web = rootSite.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Passport Details"];

        DataTable dt = list.GetItems(list.DefaultView).GetDataTable();

        DataTable dt1 = new DataTable();

        dt1.Columns.Add("EmpId", typeof(string));

        dt1.Columns.Add("EmpName", typeof(string));

        dt1.Columns.Add("passportnumber", typeof(String));

        dt1.Columns.Add("ExpiryDate", typeof(String));

        dt1.Columns.Add("ID", typeof(String));

        foreach (DataRow dr in dt.Rows)

        {

            string name = Session["empname"].ToString();

            if (dr["EmpName"].Equals(name))

            {

                SPListItem item=list.Items.GetItemById(Convert.ToInt32(dr["ID"]));

                DataRow dr1=dt1.NewRow();

                dr1["EmpId"] = item["EmpId"];

                dr1["EmpName"] = item["EmpName"];

                dr1["passportnumber"] = item["Passport_x0020_Number"];

                dr1["ExpiryDate"] = item["Expiry_x0020_Date"];

                dr1["ID"] = item["ID"];

                dt1.Rows.Add(dr1);

            }

        }

        Grid_passportdetails.DataSource = dt1;

        Grid_passportdetails.DataBind();

        return Grid_passportdetails;

    }

 

Deploy the webpart

 

   UserControl myuc;

        protected override void CreateChildControls()

        {

            myuc = (UserControl)Page.LoadControl(@"\accordion\accordioncontrol1.ascx");

            Controls.Add(myuc);

        }

        protected override void Render(HtmlTextWriter writer)

        {

            myuc.RenderControl(writer);

        }

 

 

 

Write the connection in web.config:

 

In web.config file:

 

      <appSettings/>

  <connectionStrings>

    <add name="myconnection" connectionString="Data Source=192.168.0.111;Initial Catalog=obul1;User ID=sharepoint;Password=sharePoint"/>

  </connectionStrings>

 

 

 

 

var con = System.Configuration.ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;

        SqlDataAdapter da = new SqlDataAdapter("select * from emp",con);

        DataSet ds = new DataSet();

        da.Fill(ds);

        GridView1.DataSource = ds;

        GridView1.DataBind();

 

 

Another:

{

ConfigurationManager.AppSettings["OGCMSExecutiveSearch"].ToString()

}

 

Another:

 

System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString());

Link button dynamically added and command

 

  protected LinkButton createlinks(string name, string path)

    {

 

        LinkButton lb = new LinkButton();

        lb.ID = name;

 

        lb.CommandArgument = path;

       

        lb.Command += new CommandEventHandler(lb_Command);

        lb.Text = name;

        return lb;

    }

 

    void lb_Command(object sender, CommandEventArgs e)

    {

        fileopen(e.CommandArgument.ToString());

    }

 

    public void lb_Click(object sender, EventArgs e)

    {

        LinkButton lbtn = (LinkButton)sender;

        fileopen(lbtn.CommandArgument.ToString());

    }

 

Open pop up in nextpage:

Same page:

    <li><a href="javascript:openpop()">HELP</a></li>

<script type="text/javascript">

   function openpop()

    {

        window.open("AdminHelp.aspx", "HelpDetails", "location=no,menubar=no,width=900,height=650,resizable=yes,scrollbars=yes");

    }

</script>

Open popup:

 

  <li><a href="javascript:openpop()">HELP</a></li>

 

<script type="text/javascript">

    function openpop() {

        window.open("UserHelp.aspx", "HelpDetails", "location=no,menubar=no,width=900,height=650,resizable=yes,scrollbars=yes");

    }

</script>

 

Confirm box

 

<asp:Button ID="Btnexit" runat="server" Text="Exit" ForeColor="White"

                                     BackColor="#007BA7" OnClientClick="javascript:return confirmbox()"

                                     onclick="Btnexit_Click" CausesValidation="true"/>

(or)

      <asp:Button ID="Btncancel" ForeColor="#6B696B"  runat="server" Text="Cancel" OnClientClick="javascript:return confirmcancel()"

                    onclick="Btncancel_Click" CausesValidation="False"  />

 

Javascript:

function confirmbox() {

                var result = confirm("Are you Sure you want to Exit");

                if (result) {

                    return true;

                    }

                    else

                    {

                        return false;

                    }

                }

 

 

Imp:open popup: in gridview:

 

 

   <asp:TemplateField>

        <ItemTemplate>

        <asp:HyperLink ID="hylnk" runat="server" Text="google" NavigateUrl="javascript:openpopup()"></asp:HyperLink>

        </ItemTemplate>

        </asp:TemplateField>

 

Or link button

 

  <asp:TemplateField>

        <ItemTemplate>

        <asp:LinkButton ID="lnkbtn" runat="server" Text="Google" PostBackUrl="javascript:openpopup()"></asp:LinkButton>

        </ItemTemplate>

        </asp:TemplateField>

<script type="text/javascript">

        function openpopup() {

            window.open("http://www.google.com");

        }

    </script>

 

Openpopup:

 

Same page:write page load

Viewcandidte.aspx

 

<asp:Image ID="Image1" runat="server" ToolTip="Search" ImageUrl="~/IMAGES/lookup.jpg" />

 

Viewcandidte.aspx

 

In pageload()

{

this.Image1.Attributes.Add("onclick", "javascript:return OpenPopup()");

}

 

        function OpenPopup() {

 

            window.open("PositionSearch.aspx", "List", "scrollbars=yes,resizable=yes,width=600,height=400");

 

            return false;

 

        }

 

Copyrights

 

@c 2011 option group

  <div class="Footer"> &copy; 2011 Options Group</div>

 

Using sqlhelper:

 

 

SqlParameter[] param = new SqlParameter[2];

        param[0] = new SqlParameter("@PUserId", SqlDbType.Int);

        param[0].Value = userid;

 

        param[1] = new SqlParameter("@PApplicant", SqlDbType.Int);

        param[1].Value = ApplicantID;

 

      

 

 

        SqlHelper.ExecuteNonQuery(ogconnection, CommandType.StoredProcedure, "usp_claimedapplicant", param);

 

Usign sqlhelper output parameter

 

SqlParameter[] param = new SqlParameter[2];

        param[0] = new SqlParameter("@PSubmissionId", SqlDbType.Int);

        param[0].Value = subid;

        param[1] = new SqlParameter("@count", SqlDbType.Int);

        param[1].Direction = ParameterDirection.Output;

        SqlHelper.ExecuteScalar(ogconnection, CommandType.StoredProcedure, "usp_IsApplicantClaimed", param);

        int i = Convert.ToInt32(param[1].Value);

        if (i > 0)

        {

            return true;

        }

        else

        {

            return false;

        }

 

Deploy the webpart

  UserControl myuc;

        protected override void CreateChildControls()

        {

            myuc = (UserControl)Page.LoadControl(@"\absusercontrol\createnewappoint1.ascx");

            Controls.Add(myuc);

        }

        protected override void Render(HtmlTextWriter writer)

        {

            myuc.RenderControl(writer);

        }

 

 

Sqlhelper using parameters

 

 

 

SqlParameter[] parameters = new SqlParameter[1];

        parameters[0] = new SqlParameter("@PApplicantid", SqlDbType.Int);

        parameters[0].Value = ApplicantId;

        DataSet getApplicantdata = SqlHelper.ExecuteDataset(OGconnection, CommandType.StoredProcedure, "usp_getapplicantdetails", parameters);

        return getApplicantdata;

style sheet:

 

<table align="center" style="background-color: #F0F8FF">

 

Asynchronous postback trigger

 

   <Triggers>

            <%-- <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />--%>

            <asp:PostBackTrigger ControlID="btnsubmit" />

            <%-- <asp:PostBackTrigger ControlID="lnkResume_Click" />--%>

        </Triggers>

 

Sqlserver insert

 

create procedure insertemp3

(@ename varchar(50),@esal int,@deptno int)

as

begin

insert into emp(ename,esal,deptno)values(@ename,@esal,@deptno)

end

execution: exec insertemp3 'fff',20000,10

 

update

 

create procedure updateemp

(@eno int,@ename varchar(50),@esal int,@deptno int)

as

begin

update emp set ename=@ename,esal=@esal,deptno=@deptno where @eno=eno

end

 

exec updateemp 58,'eee',100,30

 

delete

create procedure deleteemp

(@eno int)

as

begin

delete emp where eno=@eno

end

exec deleteemp 58

 

find

create procedure findemp3

(@eno int,@ename varchar(20) output,@esal int output,@deptno int output)

as

begin

select @ename=ename,@esal=esal,@deptno=deptno from emp where eno=@eno

end

declare @ename varchar(20),@esal int,@deptno int

exec findemp3 42,@ename output,@esal output,@deptno  output

print @ename

print @esal

print @deptno

print 42

 

passing the values in storedprocedure

 

protected void btn_insert_Click(object sender, EventArgs e)

    {

        try

        {

            lb_text.Text = "";

            SqlConnection con = new SqlConnection("User Id=sharepoint;password=sharePoint;database=EMS; server=192.168.0.111");

            SqlCommand cmd = new SqlCommand("AddEmp", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@emp_personal_id", 0);

            cmd.Parameters.AddWithValue("@emp_id", 0);

            cmd.Parameters.AddWithValue("@emp_fname", txt_ename.Text);

            cmd.Parameters.AddWithValue("@emp_lname", txt_elname.Text);

            cmd.Parameters.AddWithValue("@emp_mname", txt_emname.Text);

            cmd.Parameters.AddWithValue("@emp_join_date", DateTime.Parse(txt_ejdate.Text));

            cmd.Parameters.AddWithValue("@emp_dob", DateTime.Parse(txt_edateofbirth.Text));

            cmd.Parameters.AddWithValue("@emp_email", txt_eemail.Text);

            cmd.Parameters.AddWithValue("@emp_contactno", txt_econtactno.Text);

            cmd.Parameters.AddWithValue("@emp_ext", int.Parse(txt_eextention.Text));

            cmd.Parameters.AddWithValue("@emp_current_project", txt_ecproject.Text);

            cmd.Parameters.AddWithValue("@emp_address", txt_eaddress.Text);

            cmd.Parameters.AddWithValue("@emp_city", txt_ecity.Text);

            cmd.Parameters.AddWithValue("@emp_city_pincode", txt_ecitypin.Text);

            cmd.Parameters.AddWithValue("@emp_gender", ddl_egender.SelectedItem.Text);

            cmd.Parameters.AddWithValue("@emp_marital_status", ddl_emaritalstatus.SelectedItem.Text);

            con.Open();

            int i = cmd.ExecuteNonQuery();

            con.Close();

            clear();

            lb_text.Text = "Employee Inserted";

            emppersonaldetails.Visible = false;

            empgendetails.Visible = true;

           

           

      }

        catch(Exception ex)

            {

                lb_text.Text =ex.Message;

            }

 

    }

 

 

 

 

 

images slideshow in usercontrol(javascript)

 

 

    <script type="text/javascript">

        var image1 = new Image()

 

        image1.src = "http://sys-pc:1919/images/ems1.jpg"

        var image2 = new Image()

        image2.src = "http://sys-pc:1919/images/_KTZ1702.jpg"

        var image3 = new Image()

        image3.src = "http://sys-pc:1919/images/multimedia06.jpg"

        var image4 = new Image()

        image4.src = "http://sys-pc:1919/images/PORT2.jpg"

 

    </script>

 

 

<body >

<img src="http://sys-pc:1919/images/ems1.jpg" name="slide" width="700" height="400" />

<script type="text/javascript">

    var step = 1

    function slideit() {

        //if browser does not support the image object, exit.

        if (!document.images)

            return

        document.images.slide.src = eval("image" + step + ".src")

        if (step < 4)

            step++

        else

            step = 1

        //call function "slideit()" every 2.5 seconds

        setTimeout("slideit()", 2500)

    }

    slideit()

 

</script>

  

</body>

 

Css:

 

BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"

 

BackColor="#6B696B"

 

Sql datasource

 

  <asp:SqlDataSource

            ID="SqlDataSource1" 

            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

            SelectCommand="SELECT * FROM [Movies]"

            runat="server">

        </asp:SqlDataSource>

 

    <cc1:ComboBox 
            ID="ComboBox1"
            DataSourceID="SqlDataSource1" 
            DataTextField="Title" 
            DataValueField="Id" 
            MaxLength="0" 
            style="display: inline;" 
            runat="server" >
        </cc1:ComboBox>

Query string string.format:

 

  hylnkBook.NavigateUrl = string.Format("default3.aspx?" + "ConferenceRoomName={0}&SelectDate={1}&StartTime={2}", DDL_conferenceroms.SelectedItem.ToString(), Convert.ToDateTime(txt_SelectDate.Text), i.ToString());

 

Querystring using normal format

 

   Response.Redirect("default3.aspx?SelectDate=" + txt_SelectDate.Text + "&StartTime=" + ddl_starttime.SelectedValue + "&endtime=" + DDL_Endtime.SelectedValue + "&ConferenceRoomName=" + DDL_conferenceroms.SelectedItem.ToString());

Asptable add row

 

  TableRow tr = new TableRow();

        TableCell tc = new TableCell();

        tc.Text = txt_SelectDate.Text;

        tc.ForeColor = System.Drawing.Color.Orange;

        tc.ColumnSpan = 2;

        tr.Cells.Add(tc);

        tc = new TableCell();

        tc.Text = DDL_conferenceroms.SelectedItem.ToString();

        tc.ColumnSpan = 21;

        tc.HorizontalAlign = HorizontalAlign.Center;

        tc.ForeColor = System.Drawing.Color.Orange;

        tr.Cells.Add(tc);

        Table1.Rows.Add(tr);

 

Window application  click on button go to nextpage  and insert data come to firstpage(add gridview record)

If click on selected row gridview go to nextpage  and update firstpage gridview is updated

 

 

        private void button1_Click(object sender, EventArgs e)

        {

            obj = new nextpage1();

            obj.Show();

            obj.btnupdate.Visible = false;

            obj.btninsert.Click += new EventHandler(btninsert_Click);

        }

 

        void btninsert_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("User Id=sa;password=abc;database=obul1;server=SYS-PC\\SQLEXPRESS");

            string s = "insert into studentgeninformation values('" + obj.txtusername.Text + "','" + obj.txtphoneno.Text + "','" + obj.txtphoneno.Text + "','" + obj.txtemail.Text + "')";

            SqlCommand cmd = new SqlCommand(s, con);

            con.Open();

            cmd.ExecuteNonQuery();                  

            bindgridview();

            con.Close();

            obj.Close();

        }

        protected DataGridView bindgridview()

        {

           SqlConnection con=new SqlConnection ("User Id=sa;password=abc;database=obul1;server=SYS-PC\\SQLEXPRESS");

           string s = "select * from studentgeninformation";

           SqlCommand cmd = new SqlCommand(s, con);   

           SqlDataAdapter da = new SqlDataAdapter(cmd);

           DataSet ds = new DataSet();

           da.Fill(ds);

           dataGridView1.DataSource = ds.Tables[0];

           return dataGridView1;

     

        }

 

       private void dataGridView1_MouseClick(object sender, MouseEventArgs e)

        {

            obj = new nextpage1();

            obj.Show();

            obj.txtusername.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

            obj.txtpassword.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

            obj.txtphoneno.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();

            obj.txtemail.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();

            obj.btninsert.Visible = false;

            obj.btnupdate.Visible = true;

            obj.btnupdate.Click += new EventHandler(btnupdate_Click);

        }

 

        void btnupdate_Click(object sender, EventArgs e)

        {

 

            //obj = new nextpage1();

            //obj.Show();

            string s = "update studentgeninformation set lastname='" + obj.txtpassword.Text + "',phoneno='" + obj.txtphoneno.Text + "',email='" + obj.txtemail.Text + "' where firstname='"+obj.txtusername.Text+"'";

            SqlCommand cmd = new SqlCommand(s, con);

            con.Open();

            cmd.ExecuteNonQuery();

            con.Close();

            bindgridview();

            obj.Close();

          

 

        }

            

    }

Write the code in same page(in linkbutton or button)

obj.btninsert.Click += new EventHandler(btninsert_Click);

     void btninsert_Click(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("User Id=sa;password=abc;database=obul1;server=SYS-PC\\SQLEXPRESS");

            string s = "insert into studentgeninformation values('" + obj.txtusername.Text + "','" + obj.txtphoneno.Text + "','" + obj.txtphoneno.Text + "','" + obj.txtemail.Text + "')";

            SqlCommand cmd = new SqlCommand(s, con);

            con.Open();

            cmd.ExecuteNonQuery();                  

            bindgridview();

            con.Close();

            obj.Close();

        }

 

In nextpage access the controls(button,label,textbox) in firstpage

 

Take in button in secondpage or third page

Button properties

Modifier=internal or public

 

Flash vertex only change image

 

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

codebase="http://download.macromedia.com/pub/shockwave/cabs/f

lash/swflash.cab#version=6,0,40,0"

WIDTH="30" HEIGHT="56" id="myMovieName" VIEWASTEXT>

<PARAM NAME=movie VALUE="swf_files/admin.swf">

<PARAM NAME=quality VALUE=autohigh>

<PARAM NAME=bgcolor VALUE=black>

<PARAM NAME="menu" VALUE="false" />

<PARAM NAME=FlashVars VALUE="init=yes&check=true">

<EMBED src="swf_files/admin.swf"

FlashVars="init=yes&check=true" quality=high bgcolor=#FFFFFF

WIDTH="30" HEIGHT="56"

NAME="myMovieName" TYPE="application/x-shockwave-flash"

PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

</EMBED>

</OBJECT>

 

                                               

 

 

 

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="200" width="1000"

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"

WIDTH="30" HEIGHT="56" id="myMovieName" VIEWASTEXT>

<PARAM NAME=movie VALUE="http://www.nivista.com/images/homeflash.swf">

<PARAM NAME=quality VALUE=autohigh>

<PARAM NAME=bgcolor VALUE=black>

<PARAM NAME="menu" VALUE="false" />

<PARAM NAME=FlashVars VALUE="init=yes&check=true">

<EMBED src="http://www.nivista.com/images/homeflash.swf" FlashVars="init=yes&check=true" quality=high bgcolor=#FFFFFF WIDTH="30" HEIGHT="56"

NAME="myMovieName" TYPE="application/x-shockwave-flash"

PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

</EMBED>

</OBJECT>

 

 

 

Flash vertex finesolution:

 

          <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="100" width="1200"

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"

WIDTH="30" HEIGHT="56" id="myMovieName" VIEWASTEXT>

<PARAM NAME=movie VALUE="http://www.fine.com/flash.swf">

<PARAM NAME=quality VALUE=autohigh>

<PARAM NAME=bgcolor VALUE=black>

<PARAM NAME="menu" VALUE="false" />

<PARAM NAME=FlashVars VALUE="init=yes&check=true">

<EMBED src="http://www.fine.com/flash.swf" FlashVars="init=yes&check=true" quality=high bgcolor=#FFFFFF WIDTH="30" HEIGHT="56"

NAME="myMovieName" TYPE="application/x-shockwave-flash"

PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

</EMBED>

</OBJECT>

 

Wpf application(Insert ,update,view,delete):

<DataGrid AutoGenerateColumns="False" Height="176" HorizontalAlignment="Left" Margin="124,81,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="308" ItemsSource="{Binding}" MouseDoubleClick="dataGrid1_MouseDoubleClick" Visibility="Hidden" Background="#FFA3A347" Foreground="#FF001900" >

                 <DataGrid.Columns>

                <DataGridTextColumn Header="empno" Binding="{Binding Path=eno}" IsReadOnly="True" Foreground="Blue" ></DataGridTextColumn>

                <DataGridTextColumn Header="empname" Binding="{Binding Path=ename}" Foreground="Blue"></DataGridTextColumn>

                <DataGridTextColumn Header="empsal" Binding="{Binding Path=esal}" Foreground="Blue"></DataGridTextColumn>

                <DataGridTextColumn Header="deptno" Binding="{Binding Path=deptno}" Foreground="Blue" ></DataGridTextColumn>

          [editbutton]

                <DataGridTemplateColumn>

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

 

                            <Button Content="EDIT" Name="Editdetails" Background="Orange"  Click="EDIT_Click" Foreground="White"></Button>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

 

         [Delete button]

 

                <DataGridTemplateColumn>

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <Button Content="Delete" Name="btndelete" Click="btndelete_Click" Background="Orange" Foreground="White"></Button>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

            </DataGrid.Columns>           

           

        </DataGrid>

View button_click:

 

dataGrid1.Visibility = Visibility.Visible;

            ServiceReference3.Service1Client obj = new ServiceReference3.Service1Client();

            dataGrid1.DataContext = obj.getbinddata();

 

Editbutton_click

 

 

  private void EDIT_Click(object sender, RoutedEventArgs e)

        {

             obj = new editpage();

            DataGridRow dr = DataGridRow.GetRowContainingElement(sender as FrameworkElement);

            obj.txteno.Text = ((TextBlock)dataGrid1.Columns[0].GetCellContent(dr)).Text;

            obj.txtename.Text = ((TextBlock)dataGrid1.Columns[1].GetCellContent(dr)).Text;

            obj.txtesal.Text = ((TextBlock)dataGrid1.Columns[2].GetCellContent(dr)).Text;

            obj.txtdeptno.Text = ((TextBlock)dataGrid1.Columns[3].GetCellContent(dr)).Text;

            obj.Show();

            obj.button3.Click += new RoutedEventHandler(button3_Click);

            [button3=editpagelo unna button name]

        }

 

 

        void button3_Click(object sender, RoutedEventArgs e)

        {

            obulDataContext obj1 = new obulDataContext();

            {

                var v = from i in obj1.emps where i.eno == Convert.ToInt32(obj.txteno.Text) select i;

 

                foreach (var p in v)

                {

                    p.ename = obj.txtename.Text;

                    p.esal = Convert.ToInt32(obj.txtesal.Text);

                    p.deptno = Convert.ToInt32(obj.txtdeptno.Text);

 

                }

                obj1.SubmitChanges();

                obj.Hide();

                ServiceReference3.Service1Client obj2 = new ServiceReference3.Service1Client();

                dataGrid1.DataContext = obj2.getbinddata();

            }

 

Deletebutton_lick:

          

             private void btndelete_Click(object sender, RoutedEventArgs e)

        {

            string eno;

             DataGridRow dr = DataGridRow.GetRowContainingElement(sender as FrameworkElement);

            eno = ((TextBlock)dataGrid1.Columns[0].GetCellContent(dr)).Text;

            obulDataContext obj = new obulDataContext();

            var v = from i in obj.emps where i.eno==Convert.ToInt32(eno) select i;

            foreach (var p in v)

            {

                obj.emps.DeleteOnSubmit(p);

                obj.SubmitChanges();            

                ServiceReference3.Service1Client obj2 = new ServiceReference3.Service1Client();

                dataGrid1.DataContext = obj2.getbinddata();      

 

            }

        }

 

Insertbutton_click:[insert pagelo unna button_click]

 

   obulDataContext obj = new obulDataContext();

            emp ee = new emp();

            ee.eno = Convert.ToInt32(txteno.Text);

            ee.ename = txtename.Text;

            ee.esal = Convert.ToInt32(txtesal.Text);

            ee.deptno = Convert.ToInt32(txtdeptno.Text);

            obj.emps.InsertOnSubmit(ee);

            obj.SubmitChanges();

            MainWindow obj1 = new MainWindow();

            editpage obj2 = new editpage();

            this.Hide();

            MainWindow obj3 = new MainWindow();

            obj3.dataGrid1.Visibility = Visibility.Visible;

            ServiceReference3.Service1Client obj4 = new ServiceReference3.Service1Client();

            obj3.dataGrid1.DataContext = obj4.getbinddata();

 

cancel_click

 

  private void btncancel_Click(object sender, RoutedEventArgs e)

        {

            this.Hide();

        }

 

 

Some important

 

Silverlight  bind grid view using ado.net entity model and domain service:

 

Domainservice dc=new domain service();

  protected override void OnNavigatedTo(NavigationEventArgs e)

        {

            LoadOperation<emp> lo = dc.Load(dc.GetEmpsQuery(), true);

            lo.Completed += new System.EventHandler(lo_Completed);

           

        }

 

        void lo_Completed(object sender, System.EventArgs e)

        {

            IEnumerable<emp> lo = ((LoadOperation<emp>)sender).Entities;

            dgHalls.ItemsSource = lo;

 

        }

 

Ria services in silverlight

 

http://www.silverlight.net/learn/advanced-techniques/wcf-ria-services/net-ria-services-intro

 

datagrid in silverlight:

<Grid>

        <Button Content="viewdetails" Height="23" HorizontalAlignment="Left" Margin="142,38,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" Background="Orange" Foreground="White" />

        <DataGrid AutoGenerateColumns="False" Height="176" HorizontalAlignment="Left" Margin="124,81,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="308" ItemsSource="{Binding}" MouseDoubleClick="dataGrid1_MouseDoubleClick" Visibility="Hidden" Background="#FFA3A347" Foreground="#FF001900" >

                 <DataGrid.Columns>

                <DataGridTextColumn Header="empno" Binding="{Binding Path=eno}" IsReadOnly="True" Foreground="Blue" ></DataGridTextColumn>

                <DataGridTextColumn Header="empname" Binding="{Binding Path=ename}" Foreground="Blue"></DataGridTextColumn>

                <DataGridTextColumn Header="empsal" Binding="{Binding Path=esal}" Foreground="Blue"></DataGridTextColumn>

                <DataGridTextColumn Header="deptno" Binding="{Binding Path=deptno}" Foreground="Blue" ></DataGridTextColumn>

                <DataGridTemplateColumn>

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <Button Content="EDIT" Name="Editdetails" Background="Orange"  Click="EDIT_Click" Foreground="White"></Button>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

                <DataGridTemplateColumn>

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <Button Content="Delete" Name="btndelete" Click="btndelete_Click" Background="Orange" Foreground="White"></Button>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

            </DataGrid.Columns>

           

           

        </DataGrid>

        <Button Content="Insert" Height="23" HorizontalAlignment="Left" Margin="279,38,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" Background="Orange" Foreground="White" />

    </Grid>

 

 

datagrid commandnames[edit,delete]in wpf or silverlight

<sdk:DataGridTemplateColumn>

                    <sdk:DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <HyperlinkButton Click="HyperlinkButton_Click">Edit</HyperlinkButton>

                        </DataTemplate>

                    </sdk:DataGridTemplateColumn.CellTemplate>

                </sdk:DataGrid

TemplateColumn>

 

 

       private void btnUpdate_Click(object sender, RoutedEventArgs e)

        {

            uw = new UpdateStd();

            uw.textBox1.Text = stdobj.sname;

            uw.textBox2.Text = stdobj.course;

            uw.textBox3.Text = stdobj.sid.ToString();

            uw.Left = 400;

            uw.Top = 200;

            uw.Show();

            uw.btnUpdate1.Click += new RoutedEventHandler(btnUpdate1_Click);

        }

 

 

:   DataGridRow dr=DataGridRow.GetRowContainingElement(sender as FrameworkElement);

 

           r.textBox1.Text =((TextBlock)dataGrid1.Columns[0].GetCellContent(dr)).Text;

           r.txtpwd.Password = ((TextBlock)dataGrid1.Columns[1].GetCellContent(dr)).Text;

           r.txtcpwd.Password = ((TextBlock)dataGrid1.Columns[2].GetCellContent(dr)).Text;

           r.textBox4.Text = ((TextBlock)dataGrid1.Columns[3].GetCellContent(dr)).Text;

 

Two datagridviews if one or more rows deleted in first gridview same rows added with second gridview in windows form applications and eno check:

 

 

     protected  void Form1_Load(object sender, EventArgs e)

        {

            bindgridview();

            bidngridview1();

            DataGridViewCheckBoxColumn doWork = new DataGridViewCheckBoxColumn();

            doWork.HeaderText = "Delete";

            doWork.FalseValue = "0";

            doWork.TrueValue = "1";

            dataGridView1.Columns.Insert(4, doWork);

 

        }

     protected void button1_Click(object sender, EventArgs e)

        {

            int rowcount=0;

            foreach (DataGridViewRow row in dataGridView1.Rows)

            {          

                if ((row.Cells[0].Value=="1"))

                {

  rowcount++;

                    DataGridViewRow dr = (DataGridViewRow)row;

                    empno = Convert.ToInt32(dr.Cells[0].Value);

                    empname = dr.Cells[1].Value.ToString();

                    empsal = Convert.ToInt32(dr.Cells[2].Value);

                    deptnum = Convert.ToInt32(dr.Cells[3].Value);

                    string s = "delete from emp where eno=" + empno;

                    string s1 = "insert into emp1 values(" + empno + ",'" + empname + "'," + empsal + "," + deptnum + ")";

                    SqlCommand cmd2 = new SqlCommand("select eno from emp1 where eno="+empno, con);

                    con.Open();

                    int empnum =Convert.ToInt32(cmd2.ExecuteScalar());

                    if (empnum != 0)

                    {

                        MessageBox.Show("Already entered" + empnum);

                        con.Close();

                        return;

                    }

                    cmd = new SqlCommand(s, con);

                    SqlCommand cmd1 = new SqlCommand(s1, con);

              

                    int delete = cmd.ExecuteNonQuery();

                    cmd1.ExecuteNonQuery();

                    con.Close();        

             

             

                }            

 

            }

            if (rowcount == 0)

            {

                MessageBox.Show("please select checkbox");

                return;

            }

            bindgridview();

            bidngridview1(); 

      

        }

Connection string in 3-tier architecture

 

public string DBgetConnectionString()

{

string ConnectionString = "";

try

{

ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ToString();

}

catch (Exception ex)

{

throw ex;

}

return ConnectionString;

}

public string DBgetConnectionString()

{

string ConnectionString = "";

try

{

ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ToString();

}

catch (Exception ex)

{

throw ex;

}

return ConnectionString;

}

Gridview dynamically added  columns and rows:

  protected  void Form1_Load(object sender, EventArgs e)

        {

                   

            DataGridViewCheckBoxColumn doWork = new DataGridViewCheckBoxColumn();

            doWork.HeaderText = "Delete";

            doWork.FalseValue = "0";

            doWork.TrueValue = "1";      

            dataGridView1.Columns.Add("0","empno");

            dataGridView1.Columns.Add("1", "empname");

            dataGridView1.Columns.Add("2", "empsal");

            dataGridView1.Columns.Add("3","Deptno");

            dataGridView1.Columns.Insert(4, doWork);

            bindgridview();

            bidngridview1();

 

        }

      protected void bindgridview()

      {        

          SqlCommand cmd = new SqlCommand("select * from emp", con);

          da = new SqlDataAdapter(cmd);

          ds = new DataSet();

          da.Fill(ds);

 

          for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

          {

               DataGridViewRow dr = new DataGridViewRow ();

              dataGridView1.Rows.Add(dr);

              for (int j = 0; j < 4; j++)

              {

                  dataGridView1.Rows[i].Cells[j].Value = ds.Tables[0].Rows[i][j];

              }

          }

     

      }

Flash vertex in object:

 

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="250" width="1300"

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"

WIDTH="30" HEIGHT="56" id="myMovieName" VIEWASTEXT>

<PARAM NAME=movie VALUE="http://sys-pc:1919/ClientBin/flashvortex(3).swf">

<PARAM NAME=quality VALUE=autohigh>

<PARAM NAME=bgcolor VALUE=black>

<PARAM NAME="menu" VALUE="false" />

<PARAM NAME=FlashVars VALUE="init=yes&check=true">

<EMBED src="http://sys-pc:1919/ClientBin/flashvortex(3).swf" FlashVars="init=yes&check=true" quality=high bgcolor=#FFFFFF WIDTH="30" HEIGHT="56"

NAME="myMovieName" TYPE="application/x-shockwave-flash"

PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

</EMBED>

</OBJECT>

 

Flash vertex in object:

 

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="250" width="1300"

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"

WIDTH="30" HEIGHT="56" id="myMovieName" VIEWASTEXT>

<PARAM NAME=movie VALUE="http://sys-pc:1919/ClientBin/flashvortex(9).swf">

<PARAM NAME=quality VALUE=autohigh>

<PARAM NAME=bgcolor VALUE=black>

<PARAM NAME="menu" VALUE="false" />

<PARAM NAME=FlashVars VALUE="init=yes&check=true">

<EMBED src="http://sys-pc:1919/ClientBin/flashvortex(9).swf" FlashVars="init=yes&check=true" quality=high bgcolor=#FFFFFF WIDTH="30" HEIGHT="56"

NAME="myMovieName" TYPE="application/x-shockwave-flash"

PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">

</EMBED>

</OBJECT>

 

Event receiver item updated

 

base.ItemUpdated(properties);

         //SPWeb web1 = SPContext.Current.Web;

         //  SPSite site = new SPSite(@"http://demoshare:7272/Human%20Resource/");

           SPWeb web = properties.OpenWeb();

           web.AllowUnsafeUpdates = true;

           SPList tasklist = web.Lists[properties.ListTitle.ToString()];

           SPList list_ApplyLeaveHR = web.Lists["Apply Leave_HR"];

           SPList list_ApplyLeave = web.Lists["Apply Leaves_Software"];

           SPList list_ApplyLeaveCMs = web.Lists["Apply Leave_CMS"];

           SPList list_EmpLeave = web.Lists["EmployeeLeave"];  

       

           if (tasklist.Title.ToString() == "Approve/Reject Leaves")

           {

               SPListItem listItem = properties.ListItem;

               if (listItem["Outcome"].ToString() == "Approved")

 

 

Onmouseover and onmouseout in html[Marquee direction]

 

<FONT color=teal size=4><MARQUEE WIDTH=100% color=#6699CC behaviour=alternative   scrollamount=8 onmouseover=this.stop(); onmouseout=this.start();></br>

 

<marquee direction="up" onmouseover=this.stop(); onmouseout=this.start();>

<FONT color=teal size=4><MARQUEE WIDTH=100% color=#6699CC behaviour=alternative   scrollamount=8 onmouseover=this.stop(); onmouseout=this.start();></br>

 

Caml queries in tasklist:[console Application]

static void Main(string[] args)

        {

            SPSite site = new SPSite("http://sys-pc:1919/samples");

            SPWeb web = site.OpenWeb();

            web.AllowUnsafeUpdates = true;

            SPList list = web.Lists["Tasks"];

            string status = "completed";

            SPQuery myquery = new SPQuery();

            myquery.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>title2</Value></Eq></Where>";

            SPListItemCollection items = list.GetItems(myquery);

            foreach (SPListItem item in items)           

            Console.WriteLine(item["Title"].ToString());  

           

            Console.Read();

        }

 

In usercontrol

 

 

        SPSite site = new SPSite("http://sys-pc:1919/samples");

        SPWeb web = site.OpenWeb();

        web.AllowUnsafeUpdates = true;

        SPList list = web.Lists["Tasks"];

        string status = "completed";

        SPQuery myquery = new SPQuery();

        myquery.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>title2</Value></Eq></Where>";

       

        SPListItemCollection items = list.GetItems(myquery);

        foreach (SPListItem item in items)

        {

          DropDownList1.Items.Add(item["Title"].ToString());

          DropDownList2.Items.Add(item["Assigned To"].ToString());

          DropDownList3.Items.Add(item["Priority"].ToString());

        }

 

 

 

 

 

 

Remove the calender columns in sharepoint:

(Paste the code in below zone template and above img tag)

<script type="text/javascript">

function HideField(title){

var header_h3=document.getElementsByTagName("h3") ;

 

for(var i = 0; i <header_h3.length; i++)

{

    var el = header_h3[i];

    var foundField ;

   if(el.className=="ms-standardheader")

    {

        for(var j=0; j<el.childNodes.length; j++)

        {

            if(el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title)

            {

                var elRow = el.parentNode.parentNode ;

                elRow.style.display = "none"; //and hide the row

                foundField = true ;

                break;

            }

        }       

    }

    if(foundField)

        break ;

}

}

 

HideField("All Day Event");

HideField("Recurrence") ;

HideField("Workspace") ;

</script>

Download and View:

 

  protected void GridViewItems_RowCommand(object sender, GridViewCommandEventArgs e)

    {

 

        if (e.CommandName.Equals("Download") || e.CommandName.Equals("View"))

        {

            if (url == null)

            {

                url = e.CommandArgument.ToString();

            }

            Response.Redirect(url);

        }

      

    }

 

Javascript validations

 

 

       

 

<script language="javascript" type="text/javascript">

        function validate() {

            if (document.getElementById("<%=txtName.ClientID%>").value == "") {

                alert("Name Feild can not be blank");

                document.getElementById("<%=txtName.ClientID%>").focus();

                return false;

            }

            if (document.getElementById("<%=txtEmail.ClientID %>").value == "") {

                alert("Email id can not be blank");

                document.getElementById("<%=txtEmail.ClientID %>").focus();

                return false;

            }

            var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;

            var emailid = document.getElementById("<%=txtEmail.ClientID %>").value;

            var matchArray = emailid.match(emailPat);

            if (matchArray == null) {

                alert("Your email address seems incorrect. Please try again.");

                document.getElementById("<%=txtEmail.ClientID %>").focus();

                return false;

            }

            if (document.getElementById("<%=txtWebURL.ClientID %>").value == "") {

                alert("Web URL can not be blank");

                document.getElementById("<%=txtWebURL.ClientID %>").value = "http://"

                document.getElementById("<%=txtWebURL.ClientID %>").focus();

                return false;

            }

            var Url = "^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"

            var tempURL = document.getElementById("<%=txtWebURL.ClientID%>").value;

            var matchURL = tempURL.match(Url);

            if (matchURL == null) {

                alert("Web URL does not look valid");

                document.getElementById("<%=txtWebURL.ClientID %>").focus();

                return false;

            }

            if (document.getElementById("<%=txtZIP.ClientID%>").value == "") {

                alert("Zip Code is not valid");

                document.getElementById("<%=txtZIP.ClientID%>").focus();

                return false;

            }

            var digits = "0123456789";

            var temp;

            for (var i = 0; i < document.getElementById("<%=txtZIP.ClientID %>").value.length; i++) {

                temp = document.getElementById("<%=txtZIP.ClientID%>").value.substring(i, i + 1);

                if (digits.indexOf(temp) == -1) {

                    alert("Please enter correct zip code");

                    document.getElementById("<%=txtZIP.ClientID%>").focus();

                    return false;

                }

            }

            return true;

        }

 

       

</script>

 

Jquery:[add content editor webpart]

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

-------------------------------------------------------------------------------------------------------------

<html >

<HEAD runat="server">

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

 

<script type="text/javascript">

    $(document).ready(function() {

        $("button").click(function() {

            $("p").hide();

    });

});

</script>

</HEAD >

<body>

  <h2>This is a Heading</h2>

    <p>This is Anwar Hussain</p>

    <p>This is obulreddy</p>

    <button>Click me</button>

   

</body>

</html>

 

In jquery  add the master page:

in masterpage under the head tag

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

 

<script type="text/javascript">

    $(document).ready(function() {

        $("button").click(function() {

            $("p").hide();

    });

});

 Under body tag

 

   <h2>This is a Heading</h2>

    <p>This is a  Anwar Hussain</p>

    <p>This is a obulreddy</p>

    <button>Click me</button>

 

 

 

 

Row change color in tasklist:or list:[background column color]

 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function(){

$Text = $("td .ms-vb2:contains('Not Started')");

$Text.css("background-color", "#461B7E");

var myelement = $Text.parent().parent();

$Text = $("td .ms-vb2:contains('Completed')");

$Text.css("background-color", "#4CC417");

$Text = $("td .ms-vb2:contains('In Progress')");

$Text.css("background-color", "#EAC117");

});

</script>

 

Highlight rows  based on columns[forecolor like (completed ,inprogress,not started)

 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function(){

$Text = $("td .ms-vb2:contains('Rejected')");

//$Text.css("background-color", "#461B7E");

$Text.css("color","red");

var myelement = $Text.parent().parent();

$Text = $("td .ms-vb2:contains('Approved')");

//$Text.css("background-color", "#4CC417");

$Text.css("color","Green");

$Text = $("td .ms-vb2:contains('Canceled')");

//$Text.css("background-color", "#4CC417");

$Text.css("color","Blue");

 

});

</script>

 

 

 

 

Disable some fields in tasklist [based on group]

 

 

<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>

<script type="text/javascript" src="http://192.168.0.11:2244/ContentManangementSystem/images/jquery.SPServices-0.6.2.js"></script>

 

<script type="text/javascript">

$(document).ready(function () {

$().SPServices({

operation: "GetGroupCollectionFromUser",

userLoginName: $().SPServices.SPGetCurrentUser(),

async: false,

completefunc: function (xData, Status) {

if ($(xData.responseXML).find("Group[Name='Content Management']").length == 1) { //Replace the "UK_Sample" with your group name will tell that user is on a particular group or not.

$('nobr:contains("Start Date")').closest('tr').hide();

$("Select[Title='Status']").attr("disabled", "disabled"); //Disabling DropDown, for dropdown we use SELECT

}

}

});

});

</script>

Get current user in sharepoint using jscript:

 

<script type="text/javascript">

var thisUserAccount = $().SPServices.SPGetCurrentUser({

            fieldName: "Name",

            debug: false

}).split("\");

$(document).ready(function() {

$("input[name='ctl00$m$g_ec88b591_e680_490d_9a67_ab564a6f4d5c$ctl00$txtusername']").attr("Readonly", "true");

$("input[name='ctl00$m$g_ec88b591_e680_490d_9a67_ab564a6f4d5c$ctl00$txtusername']").val(thisUserAccount);

});

</script>

 

 

 

 

 

Masterpage in sharepoint 2010:

 

//add the link in above head tag(copy the masterpage)    

<SharePoint:CssRegistration name="http://192.168.0.11:2244/_styles/corev4_copy(1).css" runat="server" After="corev4.css"/>

(or)

<SharePoint:CssRegistration name="http://demoshare:7272/Style Library/custom.css" runat="server" After="corev4.css"/>

//copy the corev4.css file

//first find out the .s4-ql ul.root

//this is quick launch menuitem background

.s4-ql ul.root > li > .menu-item{

 

background:url('http://192.168.0.11:2244/images/nav-bg.gif') no-repeat;

text-transform: uppercase;

color:white;

font-size:8pt;

padding:9px 15px 8px 35px;

list-style-type:none;

list-style-position: outside;

background-repeat: no-repeat;background-position: left top;

}

 

 

//this is global navigation tool bar(change the color global navigation tool bar)

.s4-tn{

background-color:#00557B;

padding:0px; margin:0px;

}

 

//change the background color of menu itemin global navigation

 

.s4-tn li.static > .menu-item{

 color:white;

 font-size:small;

 font-family:"Times New Roman";

white-space:nowrap;

border:1px solid transparent;

padding:4px 10px;

display:inline-block;

height:15px;

vertical-align:middle;

}

 

Validations in javascript using sharepoint newitem:

 

<script src="http://demoshare:7272/jquewryDocs/jquery-1.4.1.min.js" type="text/javascript"></script>

<script type="text/javascript" src="http://demoshare:7272/jquewryDocs/jquery.SPServices-0.7.1a.min.js"></script>

<script type="text/javascript">

function PreSaveAction()

            {

           

                        var contcatno=$("input[title='ContactNo']").val();

                        if($("input[title='Subject']").val()!="" && $("input[title='Reason']").val()!="" && $("input[title='ContactNo']").val()!="")

                        {

                                    if(checkPhone(contcatno))

                                    {

                                                var txtStartDate = $(":input[title='Start Date']").val();

                                                var txtEndDate = $(":input[title='End Date']").val();

                                                var one_day=1000*60*60*24;

                                                var x=txtStartDate.split("/");    

                                                var y=txtEndDate.split("/");

                                               

                                                var date1=new Date(x[2],(x[0]-1),x[1]);

                                               

                                                var date2=new Date(y[2],(y[0]-1),y[1])

                                                var month1=x[0]-1;

                                                var month2=y[0]-1;

                                                            if(date2.getTime()>=date1.getTime())

                                                            {

                                                                        _Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day));

                                                                        _Diff=_Diff+1;

                                                                       

                                                                        if(confirm("You have applied  leave for  "+_Diff+"  days."))

                                                                        {

                                                                                    return true;

                                                                        }

                                                                        else

                                                                        {

                                                                                    return false;

                                                                        }

                                                            }

                                                            else

                                                            {

                                                                        alert("End Date must be greater than Start date");

                                                                        return false;

                                                            }

                                    }

                                   

                                    else

                                    {

                                                            alert("Please enter a valid ContactNo");

                                    }

                        }

                        else

                        {

                        alert("Please enter all fields");

                                                            return false;

                        }

            }

$(document).ready(function() {

$("input[Title='Start Date']").attr("Readonly", "true");

$("input[Title='End Date']").attr("Readonly", "true");

 

 //alert("hi");

 //$("input[title='Title']").text('ok');

 

 $("input[title='ContactNo']").attr('maxlength','10');

});

function checkPhone(str)

{

 

            var phone2 = /^(\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4}))|([7-9]{1}[0-9]{9})$/;

           

 

            if (phone2.test(str)) {

           

                        return true;

                       

            } else {

 

                        return false;

            }

}

</script>

 

bdc link:

https://cmg.vlabcenter.com/manualprint.aspx?


Answers (1)