Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
Vote poll in Picture gallery web part of MS Sharepoint server
2252 Views
Code
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using System.Web;
	using System.Web.UI;
	using System.Web.UI.WebControls;
	using System.Web.UI.WebControls.WebParts;
	using Microsoft.SharePoint;
	using System.Drawing;
	using System.Data.SqlClient;
	using System.Data;
	using Microsoft.SharePoint.WebControls;
	
	namespace vote_poll
	{
	   public class vote : WebPart
	   {
	       public Label label = new Label();
	       public RadioButtonList radiolist = new RadioButtonList();
	       public Button button = new Button();
	       public Button button1 = new Button();
	       SqlConnection conn = new SqlConnection("Data Source=INBLRPIOJNJ2;Initial Catalog=master;User id=sa;Password=password@123");
	       protected override void OnInit(EventArgs e)
	       {
	           base.OnInit(e);
	           label.Text = "Who is your favourite cricketer";
	           label.ForeColor = System.Drawing.Color.Chocolate;
	           label.Font.Size = FontUnit.XLarge;
	           label.Font.Bold = true;
	           Controls.Add(label);
	           radiolist.Items.Add(new ListItem("Sachin"));
	           radiolist.Items.Add(new ListItem("Dravid"));
	           radiolist.Items.Add(new ListItem("Dhoni"));
	           Controls.Add(radiolist);
	           button.Click += new EventHandler(button_Click);
	           button.Text = "Vote";
	           button.ForeColor = Color.White;
	           button.Font.Bold = true;
	           button.BackColor = Color.FromArgb(79, 129, 189);
	           button.BorderColor = Color.FromArgb(56, 93, 138);
	           button.CausesValidation = true;
	           Controls.Add(button);
	           button1.Click += new EventHandler(button1_Click);
	           button1.Text = "Reset";
	           button1.ForeColor = Color.White;
	           button1.Font.Bold = true;
	           button1.BackColor = Color.FromArgb(79, 129, 189);
	           button1.BorderColor = Color.FromArgb(56, 93, 138);
	           Controls.Add(button1);
	       }
	       void button1_Click(object sender, EventArgs e)
	       {
	           radiolist.ClearSelection();
	       }
	       void button_Click(object sender, EventArgs e)
	       {
	           SPWeb theSite = SPControl.GetContextWeb(Context);
	           SPUser theUser = theSite.CurrentUser;
	           string strUserName = theUser.LoginName;
	           conn.Open();
	           SqlCommand cmd = new SqlCommand("insert into radio values("+radiolist.SelectedIndex+",'"+strUserName+"')",conn);
	           cmd.ExecuteNonQuery();
	           conn.Close();
	           radiolist.ClearSelection();
	       }
	       protected override void OnLoad(EventArgs e)
	       {
	           base.OnLoad(e);
	       }
	       protected override void CreateChildControls()
	       {
	           base.CreateChildControls();
	       }
	       protected override void Render(HtmlTextWriter writer)
	       {
	           EnsureChildControls();
	           string y="";
	           SPWeb theSite = SPControl.GetContextWeb(Context);
	           SPUser theUser = theSite.CurrentUser;
	           string strUserName = theUser.LoginName;
	           conn.Open();
	           SqlCommand cmd = new SqlCommand("select count(*) from radio where username='" + strUserName + "'",conn);
	           SqlCommand cmdd = new SqlCommand("select indexx from radio where username='" + strUserName + "'", conn);
	           SqlCommand sachin = new SqlCommand("select count(indexx) from radio where indexx=0",conn);
	           SqlCommand dravid = new SqlCommand("select count(indexx) from radio where indexx=1",conn);
	           SqlCommand dhoni = new SqlCommand("select count(indexx) from radio where indexx=2",conn);
	           int check =Convert.ToInt16(cmd.ExecuteScalar());
	           int x=Convert.ToInt16(cmdd.ExecuteScalar());
	           int sa=Convert.ToInt16(sachin.ExecuteScalar());
	           int dr = Convert.ToInt16(dravid.ExecuteScalar());
	           int dh = Convert.ToInt16(dhoni.ExecuteScalar());
	           if(x==0)
	               y="Sachin";
	           if (x == 1)
	               y = "Dravid";
	           if (x == 2)
	               y = "Dhoni";
	           if (check==1)
	           {
	               writer.Write("You Have voted to "+y+"");
	               writer.Write("<br/>");
	               writer.Write("Thanks for voting.....");
	               writer.Write("<br/>");
	               writer.Write("Sachin votes:"+sa+"");
	               writer.Write("<br/>");
	               writer.Write("Dravid votes:"+dr+"");
	               writer.Write("<br/>");
	               writer.Write("Dhoni votes:"+dh+"");
	           }
	           else
	           {
	               label.RenderControl(writer);
	               radiolist.RenderControl(writer);
	               button.RenderControl(writer);
	               button1.RenderControl(writer);
	           }
	       }
	   }
	}
Next Topics
Next lessons of current book.
Best solution url of MS Sharepoint server
Best solution url of MS Sharepoint server
Previous Topics
Previous lessons of current book.
Content query web part of MS Sharepoint server
Content query web part of MS Sharepoint server
Content query web part of MS Sharepoint server
Content query web part of MS Sharepoint server
Content query web part of MS Sharepoint server
Best Lessons of "MS Sharepoint server"
Top lessons which are viewed more times.
Best solution url of MS Sharepoint server
Content query web part of MS Sharepoint server
Content query web part of MS Sharepoint server
Picture gallery web part of MS Sharepoint server
Content query web part of MS Sharepoint server
Best solution url of MS Sharepoint server
Content query web part of MS Sharepoint server
Content query web part of MS Sharepoint server
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details