Tuesday, April 1, 2014

Javascript Alert in C#

1) Response.Write("<script>alert('Either User Name Or Password Is Wrong')</script>");

2) Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorMessage", "Notification('" + ex.Message + "')", true);

3) ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('Course have Subjects under it, can not change name');", true);

SETTING UP VISUAL STUDIO 2010 EXPRESS EDITION

Step 1 : It’s easy enough to download and install Visual C# 2010 Express Edition. Here’s the link to the                   Visual Studio 2010 Express Edition download page:
           
             http://www.microsoft.com/express/downloads/

             http://www.visualstudio.com/downloads/download-visual-studio-vs

Step 2 : Download the installation package for Visual C# 2010 Express Edition. Make sure you do a complete installation. That should install everything that you need: the IDE (which you’ll learn about),.NET Framework 4.0, and other tools.

Delete data using template button in gridview

Step 1 :  Add In Gridview ASPX Page


                  <asp:TemplateField>
                  <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server"
                            CommandArgument='<%# Eval("biInvitationId") %>' 
    CommandName="dele">Delete</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "dele")
        {
          string biInvitationId = e.CommandArgument.ToString();
          strResult = DeleteCourseYearDetails(entCourse); 
        }
    }

 public string DeleteCourseYearDetails(object Id)
        {
            Ent_Course entCourse = (Ent_Course)Id;

            using (SqlCommand cmd = DBhelper.Instance.GetCommand("SP_DELETE_COURSEYEAR", CommandType.StoredProcedure))
            {
                cmd.Parameters.AddWithValue("@COURSEID", entCourse.CourseId);
                cmd.Parameters.AddWithValue("@RESULT", "");
                cmd.Parameters["@Result"].Direction = ParameterDirection.Output;
                cmd.ExecuteNonQuery();
                Result = cmd.Parameters["@Result"].Value.ToString();
                DBhelper.Instance.CloseConnection(cmd);

            }
            return Result;
        }

Step 2 : Stored Procedure 

CREATE PROCEDURE [dbo].[SP_DELETE_COURSEYEAR]
 @COURSEID INT,
 @RESULT CHAR(1) OUTPUT
AS
BEGIN
 --DECLARE @COUNT INT
 --SET @RESULT='N'
 --SET @COUNT=(SELECT COUNT(*) FROM CourseYear WHERE Id=@COURSEID)
 --IF(@COUNT > 0)
  BEGIN
   DELETE FROM CourseYear WHERE Id=@COURSEID 
   
   SET @RESULT='Y'
   
  END
 
END


Make Field in Gridview Sortable

Step 1: Add SortExpression=""

 <asp:BoundField DataField="CourseId" HeaderText="Course Id" SortExpression="CourseId"
   HeaderStyle-CssClass="hideTemplateField" ItemStyle-CssClass="hideTemplateField"                                           ControlStyle-CssClass="hideTemplateField" />

Bind Database data to Gridview

Step 1: ASPX Page

  <asp:GridView ID="dgvVertical" AllowSorting="true" AllowPaging="true" PageSize="10"
                                                                        AutoGenerateColumns="false" class="table table-bordered coursesTable" Style="width: 785px;
                                                                        border-collapse: initial;" runat="server" OnRowCreated="dgvVertical_RowCreated"
                                                                        OnSorting="dgvVertical_Sorting" OnPageIndexChanging="dgvVertical_PageIndexChanging"
                                                                        PagerSettings-Mode="Numeric" PagerSettings-PageButtonCount="4">
                                                                        <PagerStyle CssClass="gridpager" HorizontalAlign="Left" />
                                                                        <RowStyle />
                                                                        <AlternatingRowStyle BackColor="#f9f9f9" />
                                                                        <PagerStyle CssClass="pager" />
                                                                        <HeaderStyle BackColor="#D6D5D6" />
                                                                        <EmptyDataTemplate>
                                                                            No Record Found
                                                                        </EmptyDataTemplate>
                                                                        <Columns>
                                                                            <asp:BoundField DataField="CourseId" HeaderText="Course Id" SortExpression="CourseId"
                                                                                HeaderStyle-CssClass="hideTemplateField" ItemStyle-CssClass="hideTemplateField"
                                                                                ControlStyle-CssClass="hideTemplateField" />
                                                                            <asp:BoundField DataField="RowNumber" HeaderText="Sr.No" SortExpression="CourseId"
                                                                                HeaderStyle-ForeColor="Black" />
                                                                            <asp:BoundField DataField="CourseName" HeaderText="Course Name" SortExpression="CourseName"
                                                                                HeaderStyle-ForeColor="Black" />
                                                                            <asp:BoundField DataField="Yearofcourse" HeaderText="Year Of The Course" SortExpression="Yearofcourse"
                                                                                HeaderStyle-ForeColor="Black" />
                                                                            <asp:BoundField DataField="SpecializationSubid" HeaderText="SpecializationSubid"
                                                                                SortExpression="SpecializationSubid" HeaderStyle-CssClass="hideTemplateField"
                                                                                ItemStyle-CssClass="hideTemplateField" ControlStyle-CssClass="hideTemplateField" />
                                                                            <%-- <asp:BoundField DataField="SpecializationSubid" HeaderText="Specialization Subject ID" SortExpression="SpecializationSubid" HeaderStyle-ForeColor="Black" />--%>
                                                                            <%--Commented by Shekhar 6/11/2013 to hide id on gridview page --%>
                                                                            <asp:BoundField DataField="specialSubject" HeaderText="Specialization Subject Name"
                                                                                SortExpression="specialSubject" HeaderStyle-ForeColor="Black" />
                                                                            <asp:BoundField DataField="courseCode" HeaderText="Course Code" SortExpression="courseCode"
                                                                                HeaderStyle-ForeColor="Black" Visible="false" />
                                                                            <asp:TemplateField HeaderText="Edit" Visible="false">
                                                                                <ItemTemplate>
                                                                                    <input id='btnEdit<%#Eval("CourseId") %>' type="image" title="Edit Course Details"
                                                                                        value="" class="icon-edit" onclick="DisplayVertical(this,'U','<%#Eval("CourseId") %>');"
                                                                                        style="width: 14px;" />
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>
                                                                            <asp:TemplateField HeaderText="Delete">
                                                                                <ItemTemplate>
                                                                                    <input id='btnDelete<%#Eval("CourseId") %>' type="image" onclick="DeleteCourse(this,'<%#Eval("CourseId") %>','D');"
                                                                                        title="Delete Course Details" value="" class="icon-remove" style="width: 14px;" />
                                                                                </ItemTemplate>
                                                                            </asp:TemplateField>
                                                                        </Columns>
                                                                    </asp:GridView>
                                                                    <table style="height: 15px; text-align: left; vertical-align: top; width: 200px;">
                                                                        <tr>
                                                                            <td style="width: 200px; height: 20px; text-align: center; vertical-align: middle;">
                                                                                <b><i>
                                                                                    <%=dgvVertical.PageIndex + 1%>
                                                                                    of
                                                                                    <%=dgvVertical.PageCount%></i></b>
                                                                            </td>
                                                                            <td style="width: 150px; height: 20px; text-align: center; vertical-align: middle;">
                                                                                <%--<input class="icon-pencil" id="btnAddNew" onmousemove="HighLight(this);" onmouseover="HighLight(this);"
                                                                        type="image" value="Add New" onclick="DisplayVertical(this,'I')"style="width: 14px;" />
                                                                                --%>
                                                                                <input type="image" class="icon-pencil" id="Image2" value="" onclick="DisplayVertical(this,'I')"
                                                                                    style="width: 15px;" />
                                                                                <asp:LinkButton ID="btnAddNew" Style="width: 20px;" Text="Add New" OnClientClick="DisplayVertical(this,'I')"
                                                                                    runat="server" />
                                                                            </td>
                                                                        </tr>
                                                                    </table>

Step 2: Bind data to grid Code on .cs page

private void BindGrid()
        {
         
            DataSet ds = GetCourseMaster();
                         
            try
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataView dv = ds.Tables[0].DefaultView;
                    if (ViewState["SortExp"] != null)
                    {
                        dv.Sort = this.ViewState["SortExp"].ToString() + " " + this.ViewState["SortOrder"].ToString();
                        dgvVertical.DataSource = dv.ToTable();
                        dgvVertical.DataBind();
                    }
                    else
                    {
                        dgvVertical.DataSource = ds;
                        dgvVertical.DataBind();
                    }
                }
                else
                {
                    dgvVertical.DataSource = null;
                    dgvVertical.DataBind();
                }
            }
            catch (Exception ex)
            {
                ErrorMessage(ex);
            }
        }

  public DataSet GetCourseMaster()
        {        
            string strQuery = @"SELECT  row_number() OVER (ORDER BY CourseMaster.CourseName) AS RowNumber,   CourseYear.Id AS CourseId, CourseMaster.CourseName, CourseYear.YearOfCourse,SubjectsMaster.SubjectName as specialSubject,
                      CourseYear.SpecializationSubId
FROM         CourseMaster INNER JOIN
                      CourseYear ON CourseMaster.CourseId = CourseYear.CourseId LEFT OUTER JOIN
                      SubjectsMaster ON CourseYear.SpecializationSubId = SubjectsMaster.Subjectid";
            using (SqlCommand cmd = GetCommand(strQuery, CommandType.Text))
            {
                ds = new DataSet();
                SqlDataAdapter SqlAdp = new SqlDataAdapter(cmd);
                SqlAdp.Fill(ds);
                DBhelper.Instance.CloseConnection(cmd);
            }
            return ds;

        }

public SqlCommand GetCommand(string spName, CommandType CommandType)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = spName;
            cmd.CommandType = CommandType;
            cmd.Connection = ConnectionString;
            return cmd;

        }

   public SqlConnection ConnectionString
        {
            get
            {

                _connectionString = new SqlConnection(Getconnect());
                _connectionString.Open();

                return _connectionString;
            }

        }

        public string Getconnect()
        {
            string connectionsring = ConfigurationManager.ConnectionStrings["Elearning"].ConnectionString;

            return connectionsring;

        }

Fill DropDown In ASP.NET

Step 1 : Create Function

       private void FillSubjects()
           {
               DataSet ds = new DataSet();
              ds = FillSubject();

              if (ds.Tables[0].Rows.Count > 0)
                {
                ddlsplsub.DataTextField = "SubjectName";
                ddlsplsub.DataValueField = "SubjectId";
                ddlsplsub.DataSource = ds;
                ddlsplsub.DataBind();

                 }
           }    

public DataSet FillSubject()
        {
            ds = new DataSet();
            try
            {
                ds = GetSubject();   //12/11/2013
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].NewRow();
                    dr["SubjectId"] = "0";
                    dr["SubjectName"] = "Select Subject";
                    ds.Tables[0].Rows.InsertAt(dr, 0);
                }
            }
            catch (Exception ex)
            {
                ds = null;
            }
            return ds;
        }


public DataSet GetSubject()
        {
            strQuery = "select  SubjectId,rtrim(SubjectName)  as SubjectName from SubjectsMaster order by subjectName asc";
            using (SqlCommand cmd = GetCommand(strQuery, CommandType.Text))
            {
                ds = new DataSet();
                SqlDataAdapter SqlAdp = new SqlDataAdapter(cmd);
                SqlAdp.Fill(ds);
                DBhelper.Instance.CloseConnection(cmd);
            }
            return ds;
        }

 public SqlCommand GetCommand(string spName, CommandType CommandType)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = spName;
            cmd.CommandType = CommandType;
            cmd.Connection = ConnectionString;
            return cmd;

        }

  public SqlConnection ConnectionString
        {
            get
            {

                _connectionString = new SqlConnection(Getconnect());
                _connectionString.Open();

                return _connectionString;
            }

        }

  public string Getconnect()
        {
            string connectionsring = ConfigurationManager.ConnectionStrings["Elearning"].ConnectionString;

            return connectionsring;

        }

Video Conferencing in ASP.NET with BigBlueButton

Step 1 : Visit https://code.google.com/p/bigbluebutton/wiki/BigBlueButtonVM Read All Instructions.

Step 2 : Please install VMware.

Step 3 : Below is the link where you'll find all the bbb-conf commands. You will need those while configuring the                BBB server. https://code.google.com/p/bigbluebutton/wiki/BBBConf

Step 4 : Download API or Project http://bigbluebutton.codeplex.com/releases/view/64151

Step 5 : If You are not able to figure out what it is then send me your mail id i will send you c# library

step 6 : Enter ServerIPAddress to ServerIPAddress.txt from VMWare Ip Address

Step 7 : Enter Salt id to ServerId.txt 

Step 8 : You will get these two IP Addresses bbb-conf commands  https://code.google.com/p/bigbluebutton/wiki/BBBConf         

Step 9 : UI Screen Show Below 

Step 10 : On Join Click Moderator i.e. admin will create meeting and join meeting and others can join it

Step 11 : Code On Join Button

 protected void btnJoin_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            ClsBigBlueButton ObjBigBlueButton = new ClsBigBlueButton();

            if (txtPwd.Text.ToUpper().Equals("MODERATOR"))
            {
                dt = ObjBigBlueButton.CreateMeeting("DemoClassroom", ddlClassrooms.Text, "student", "moderator");
                ObjBigBlueButton.JoinMeeting(txtUsername.Text, ddlClassrooms.Text, "moderator", true);
            }
            else
            {
                dt = ObjBigBlueButton.IsMeetingRunning(ddlClassrooms.Text);
                if (dt != null && dt.Rows[0][1].ToString().ToUpper().Equals("TRUE"))
                    ObjBigBlueButton.JoinMeeting(txtUsername.Text, ddlClassrooms.Text, txtPwd.Text, true);
                else
                    lblMsg.Text = "Classroom Unavailable!";
            }            
        }